diff options
| author | 2024-09-10 11:29:43 -0400 | |
|---|---|---|
| committer | 2024-09-10 11:31:20 -0400 | |
| commit | a0ff5b10f1307c12ffd464850eeec3ec66e2770f (patch) | |
| tree | cf9347863fe24ca58bdcb9650f5f7bdcbad6e28b /src/lush.c | |
| parent | added coloring to help command (diff) | |
lua api functions for getting terminal width and height
Diffstat (limited to 'src/lush.c')
| -rw-r--r-- | src/lush.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -195,6 +195,9 @@ static size_t get_prompt_len(const char *format, const char *username, } else if (strncmp(format, "%w", 2) == 0) { prompt_len += strlen(cwd); format += 2; + } else if (strncmp(format, "%t", 2) == 0) { + prompt_len += 8; // size of time format + format += 2; } else { prompt_len++; format++; @@ -230,6 +233,18 @@ static char *format_prompt_string(const char *input, const char *username, strcpy(dest, cwd); dest += strlen(cwd); input += 2; + } else if (strncmp(input, "%t", 2) == 0) { + time_t current_time; + time(¤t_time); + + struct tm *local_time = localtime(¤t_time); + + // Format the time as HH:MM:SS + char time_string[9]; // HH:MM:SS is 8 characters + null terminator + strftime(time_string, sizeof(time_string), "%H:%M:%S", local_time); + strcpy(dest, time_string); + dest += strlen(time_string); + input += 2; } else { *dest++ = *input++; } |
