Skip to content

Commit ae96fbd

Browse files
release: v2.2.0 UI/UX refresh
1 parent 9f10a57 commit ae96fbd

4 files changed

Lines changed: 84 additions & 44 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# krep - A high-performance string search utility
22
# Author: Davide Santangelo
3-
# Version: 2.1.0
3+
# Version: 2.2.0
44

55
PREFIX ?= /usr/local
66
BINDIR = $(PREFIX)/bin

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# k(r)ep - A high-performance string search utility
22

3-
![Version](https://img.shields.io/badge/version-2.1.0-blue)
3+
![Version](https://img.shields.io/badge/version-2.2.0-blue)
44
![License](https://img.shields.io/badge/license-BSD-green)
55

66
`krep` is an optimized string search utility designed for maximum throughput and efficiency when processing large files and directories. It is built with performance in mind, offering multiple search algorithms and SIMD acceleration when available.
@@ -29,9 +29,16 @@ Just as skilled fishers identify patterns in the water to locate fish quickly, I
2929
- **Gitignore support**: Respect `.gitignore` files during recursive search with `--gitignore`
3030
- **Stdin pattern input**: Read patterns from stdin with `-f -` for seamless pipeline integration
3131
- **Colored output**: Highlights matches for better readability
32+
- **UI/UX refresh (v2.2)**: New terminal color palette, clearer `-o` line index styling, and a redesigned help screen
3233
- **Specialized algorithms**: Optimized handling for single-character and short patterns
3334
- **Match Limiting**: Stop searching a file after a specific number of matching lines are found.
3435

36+
## What's New in v2.2.0
37+
38+
- Refined terminal-first UI with a cleaner, more legible color theme
39+
- Better visual hierarchy in `-o` mode (filename, line index, match highlight)
40+
- Improved `--help` layout with grouped sections and clearer scanning
41+
3542
## Installation
3643

3744
### Using Homebrew (macOS)
@@ -161,7 +168,7 @@ make bench-rg
161168
# optional: RUNS=7 bash test/benchmark_krep_vs_rg.sh Sherlock
162169
```
163170

164-
### krep v2.1.0 vs ripgrep (warm cache, 7 runs average)
171+
### krep v2.1.0 vs ripgrep (warm cache, 7 runs average baseline)
165172

166173
| Pattern | krep avg real (s) | ripgrep avg real (s) | Speedup |
167174
| --- | ---: | ---: | ---: |

krep.c

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static bool thread_pool_submit_batch(thread_pool_t *pool, void *(*func)(void *),
8080
#define LARGE_FILE_THRESHOLD (64 * 1024 * 1024) // 64MB threshold for advanced optimizations
8181
#define SINGLE_THREAD_FILE_SIZE_THRESHOLD MIN_CHUNK_SIZE
8282
#define ADAPTIVE_THREAD_FILE_SIZE_THRESHOLD 0
83-
#define VERSION "2.1.0"
83+
#define VERSION "2.2.0"
8484
#ifndef PATH_MAX
8585
#define PATH_MAX 4096
8686
#endif
@@ -501,11 +501,13 @@ size_t print_matching_items(const char *filename, const char *text, size_t text_
501501
const char *color_filename = KREP_COLOR_FILENAME;
502502
const char *color_reset = KREP_COLOR_RESET;
503503
const char *color_separator = KREP_COLOR_SEPARATOR;
504+
const char *color_line_number = KREP_COLOR_LINE_NUMBER;
504505
const char *color_text = KREP_COLOR_TEXT;
505506
const char *color_match = KREP_COLOR_MATCH;
506507

507508
// Precompute lengths to avoid repeated strlen calls
508509
size_t len_color_reset = color_output_enabled ? strlen(color_reset) : 0;
510+
size_t len_color_line_number = color_output_enabled ? strlen(color_line_number) : 0;
509511
size_t len_color_text = color_output_enabled ? strlen(color_text) : 0;
510512
size_t len_color_match = color_output_enabled ? strlen(color_match) : 0;
511513

@@ -688,7 +690,7 @@ size_t print_matching_items(const char *filename, const char *text, size_t text_
688690
size_t required_estimate = filename_prefix_len + lineno_len + len + 1; // +1 for newline
689691
if (color_output_enabled)
690692
{
691-
required_estimate += len_color_match + len_color_reset;
693+
required_estimate += len_color_line_number + len_color_match + (len_color_reset * 2);
692694
}
693695

694696
// Flush the batch buffer to stdout if the new entry won't fit (use estimate)
@@ -714,7 +716,15 @@ size_t print_matching_items(const char *filename, const char *text, size_t text_
714716
}
715717

716718
// 2. Copy line number
719+
if (color_output_enabled)
720+
{
721+
safe_append_to_batch(&current_write_ptr, batch_buffer_end, &o_batch_pos, O_BATCH_BUFFER_SIZE, color_line_number, len_color_line_number);
722+
}
717723
safe_append_to_batch(&current_write_ptr, batch_buffer_end, &o_batch_pos, O_BATCH_BUFFER_SIZE, lineno_buffer, lineno_len);
724+
if (color_output_enabled)
725+
{
726+
safe_append_to_batch(&current_write_ptr, batch_buffer_end, &o_batch_pos, O_BATCH_BUFFER_SIZE, color_reset, len_color_reset);
727+
}
718728

719729
// 3. Start color for match (if enabled)
720730
if (color_output_enabled)
@@ -1126,46 +1136,62 @@ double get_time(void)
11261136
// Print usage information
11271137
void print_usage(const char *program_name)
11281138
{
1129-
printf("krep v%s - A high-performance string search utility\n\n", VERSION);
1130-
printf("Usage: %s [OPTIONS] PATTERN [FILE | DIRECTORY]\n", program_name);
1131-
printf(" or: %s [OPTIONS] -e PATTERN [-e PATTERN...] [FILE | DIRECTORY]\n", program_name);
1132-
printf(" or: %s [OPTIONS] -f FILE [FILE | DIRECTORY]\n", program_name);
1133-
printf(" or: %s [OPTIONS] -s PATTERN STRING_TO_SEARCH\n", program_name);
1134-
printf(" or: %s [OPTIONS] PATTERN < FILE\n", program_name);
1135-
printf(" or: cat FILE | %s [OPTIONS] PATTERN\n\n", program_name);
1136-
printf("OPTIONS:\n");
1137-
printf(" -i Perform case-insensitive matching.\n");
1138-
printf(" -c Count matching lines. Only a count of lines is printed.\n");
1139-
printf(" -o Only matching. Print only the matched parts of lines, one per line.\n");
1140-
printf(" -e PATTERN Specify pattern. Can be used multiple times (treated as OR for literal, combined for regex).\n");
1141-
printf(" -f FILE Read patterns from FILE, one per line. Use '-' for stdin.\n");
1142-
printf(" -E Interpret PATTERN(s) as POSIX Extended Regular Expression(s).\n");
1143-
printf(" If multiple -e used with -E, they are combined with '|'.\n");
1144-
printf(" -F Interpret PATTERN(s) as fixed strings (literal). Default if not -E.\n");
1145-
printf(" -r Search directories recursively. Skips binary files and common dirs.\n");
1146-
printf(" --gitignore Respect .gitignore files when searching recursively (-r).\n");
1147-
printf(" --algo=ALGO Force search algorithm: 'auto' (default), 'bm', 'kmp'.\n");
1148-
printf(" -t NUM Use NUM threads for file search (default: auto-detect cores).\n");
1149-
printf(" -s Search in STRING_TO_SEARCH instead of FILE or DIRECTORY.\n");
1150-
printf(" --color[=WHEN] Control color output ('always', 'never', 'auto'). Default: 'auto'.\n");
1151-
printf(" --no-simd Explicitly disable SIMD acceleration.\n");
1152-
printf(" -v Show version information and exit.\n");
1153-
printf(" -h, --help Show this help message and exit.\n");
1154-
printf(" -m NUM Stop reading a file after NUM matching lines.\n");
1155-
printf(" -w Select only matches that form whole words.\n\n");
1156-
printf("EXIT STATUS:\n");
1157-
printf(" 0 if matches were found,\n");
1158-
printf(" 1 if no matches were found,\n");
1159-
printf(" 2 if an error occurred.\n\n");
1160-
printf("EXAMPLES:\n");
1139+
bool style = isatty(STDOUT_FILENO);
1140+
const char *title = style ? KREP_COLOR_HELP_TITLE : "";
1141+
const char *section = style ? KREP_COLOR_HELP_SECTION : "";
1142+
const char *option = style ? KREP_COLOR_HELP_OPTION : "";
1143+
const char *muted = style ? KREP_COLOR_HELP_MUTED : "";
1144+
const char *reset = style ? KREP_COLOR_RESET : "";
1145+
1146+
printf("%skrep v%s%s\n", title, VERSION, reset);
1147+
printf("%sFast search with polished terminal output.%s\n\n", muted, reset);
1148+
1149+
printf("%sUsage%s\n", section, reset);
1150+
printf(" %s [OPTIONS] PATTERN [FILE | DIRECTORY]\n", program_name);
1151+
printf(" %s [OPTIONS] -e PATTERN [-e PATTERN...] [FILE | DIRECTORY]\n", program_name);
1152+
printf(" %s [OPTIONS] -f FILE [FILE | DIRECTORY]\n", program_name);
1153+
printf(" %s [OPTIONS] -s PATTERN STRING_TO_SEARCH\n", program_name);
1154+
printf(" %s [OPTIONS] PATTERN < FILE\n", program_name);
1155+
printf(" cat FILE | %s [OPTIONS] PATTERN\n\n", program_name);
1156+
1157+
printf("%sSearch%s\n", section, reset);
1158+
printf(" %s-i%s Perform case-insensitive matching.\n", option, reset);
1159+
printf(" %s-e PATTERN%s Specify pattern. Reusable for multiple patterns.\n", option, reset);
1160+
printf(" %s-f FILE%s Read patterns from FILE (use '-' for stdin).\n", option, reset);
1161+
printf(" %s-E%s Use POSIX Extended Regular Expressions.\n", option, reset);
1162+
printf(" %s-F%s Use fixed strings (default unless -E).\n", option, reset);
1163+
printf(" %s-w%s Match whole words only.\n\n", option, reset);
1164+
1165+
printf("%sScope & Performance%s\n", section, reset);
1166+
printf(" %s-r%s Search directories recursively.\n", option, reset);
1167+
printf(" %s--gitignore%s Respect .gitignore when used with -r.\n", option, reset);
1168+
printf(" %s--algo=ALGO%s Force algorithm: auto (default), bm, kmp.\n", option, reset);
1169+
printf(" %s-t NUM%s Set thread count (default: auto).\n", option, reset);
1170+
printf(" %s--no-simd%s Disable SIMD acceleration.\n\n", option, reset);
1171+
1172+
printf("%sOutput & UX%s\n", section, reset);
1173+
printf(" %s-o%s Print only matching parts, one per line.\n", option, reset);
1174+
printf(" %s-c%s Print only match counts.\n", option, reset);
1175+
printf(" %s-m NUM%s Stop after NUM matching lines per file.\n", option, reset);
1176+
printf(" %s-s%s Search in STRING_TO_SEARCH.\n", option, reset);
1177+
printf(" %s--color[=WHEN]%s Color mode: always, never, auto (default).\n", option, reset);
1178+
printf(" %s-v%s Show version information.\n", option, reset);
1179+
printf(" %s-h, --help%s Show this help page.\n\n", option, reset);
1180+
1181+
printf("%sExit Status%s\n", section, reset);
1182+
printf(" 0 match found\n");
1183+
printf(" 1 no match found\n");
1184+
printf(" 2 error\n\n");
1185+
1186+
printf("%sExamples%s\n", section, reset);
11611187
printf(" %s \"search term\" input.log\n", program_name);
11621188
printf(" %s -i -c ERROR large_log.txt\n", program_name);
11631189
printf(" %s -t 8 -o '[0-9]+' data.log | sort | uniq -c\n", program_name);
11641190
printf(" %s -E \"^[Ee]rror: .*failed\" system.log\n", program_name);
11651191
printf(" %s -r \"MyClass\" /path/to/project\n", program_name);
11661192
printf(" %s -r --gitignore \"TODO\" /path/to/project\n", program_name);
1167-
printf(" %s -e Error -e Warning app.log\n", program_name); // Find lines with Error OR Warning
1168-
printf(" echo 'pattern' | %s -f - target.txt\n", program_name); // Read pattern from stdin
1193+
printf(" %s -e Error -e Warning app.log\n", program_name);
1194+
printf(" echo 'pattern' | %s -f - target.txt\n", program_name);
11691195
}
11701196

11711197
// Helper for case-insensitive comparison using the lookup table

krep.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@ typedef struct ac_trie ac_trie_t;
3232
/* --- ANSI Color Codes --- */
3333
// Define colors consistently
3434
#define KREP_COLOR_RESET "\033[0m"
35-
#define KREP_COLOR_FILENAME "\033[1;35m" // Magenta
36-
#define KREP_COLOR_SEPARATOR "\033[1;90m" // Bright Black (Gray)
37-
#define KREP_COLOR_MATCH "\033[1;31m" // Bright Red
38-
#define KREP_COLOR_TEXT "\033[0m" // Default terminal text color
35+
#define KREP_COLOR_FILENAME "\033[1;38;5;81m" // Bright cyan
36+
#define KREP_COLOR_SEPARATOR "\033[38;5;244m" // Muted gray
37+
#define KREP_COLOR_LINE_NUMBER "\033[1;38;5;111m" // Soft mint
38+
#define KREP_COLOR_MATCH "\033[1;38;5;222m" // Warm amber
39+
#define KREP_COLOR_TEXT "\033[38;5;252m" // Soft white
40+
41+
/* --- Help UI Colors --- */
42+
#define KREP_COLOR_HELP_TITLE "\033[1;38;5;81m"
43+
#define KREP_COLOR_HELP_SECTION "\033[1;38;5;222m"
44+
#define KREP_COLOR_HELP_OPTION "\033[1;38;5;117m"
45+
#define KREP_COLOR_HELP_MUTED "\033[38;5;244m"
3946

4047
/* --- Match tracking structure --- */
4148
// Define match_position_t BEFORE match_result_t
@@ -311,4 +318,4 @@ static inline bool is_whole_word_match(const char *text, size_t text_len, size_t
311318
return true;
312319
}
313320

314-
#endif /* KREP_H */
321+
#endif /* KREP_H */

0 commit comments

Comments
 (0)