projects
/
show-time.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
fc1e5c1
)
Exit show-time if terminal width is unknown.
master
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Mon, 27 Jun 2011 06:23:58 +0000
(08:23 +0200)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Mon, 27 Jun 2011 06:23:58 +0000
(08:23 +0200)
show-time.c
patch
|
blob
|
history
diff --git
a/show-time.c
b/show-time.c
index
4e4369f
..
9f02fc0
100644
(file)
--- a/
show-time.c
+++ b/
show-time.c
@@
-18,7
+18,7
@@
int getColumns() {
if (!error) {
return terminalSize.ws_col;
}
if (!error) {
return terminalSize.ws_col;
}
- return
80
;
+ return
-1
;
}
int main(int argc, char** argv) {
}
int main(int argc, char** argv) {
@@
-26,6
+26,7
@@
int main(int argc, char** argv) {
struct tm *localTime;
time_t currentTime;
char buffer[80];
struct tm *localTime;
time_t currentTime;
char buffer[80];
+ int terminalWidth;
if (fork() != 0) {
return 0;
if (fork() != 0) {
return 0;
@@
-36,7
+37,11
@@
int main(int argc, char** argv) {
localTime = localtime(¤tTime);
strftime(buffer, 80, "%d.%m.%Y %H:%M:%S", localTime);
printf("%c[s", 27); /* save cursor position */
localTime = localtime(¤tTime);
strftime(buffer, 80, "%d.%m.%Y %H:%M:%S", localTime);
printf("%c[s", 27); /* save cursor position */
- printf("%c[%d;%dH", 27, 1, (int) (getColumns() - strlen(buffer))); /* set cursor */
+ terminalWidth = getColumns();
+ if (terminalWidth == -1) {
+ return 0;
+ }
+ printf("%c[%d;%dH", 27, 1, (int) (terminalWidth - strlen(buffer))); /* set cursor */
printf("%s", buffer);
printf("%c[u", 27); /* restore cursor position */
fflush(stdout);
printf("%s", buffer);
printf("%c[u", 27); /* restore cursor position */
fflush(stdout);