xaizek / hstr (License: Apachev2) (since 2018-12-07)
Bash and Zsh shell history suggest box - easily view, navigate, search and manage your command history.
Commit 21ea4c288efeb75c4037b4e9ee168ee2c81347b8

Adding utf8 test.
Author: Martin Dvorak
Author date (UTC): 2014-06-07 04:08
Committer name: Martin Dvorak
Committer date (UTC): 2014-09-11 16:33
Parent(s): 5aaed1b17851e4078ee759b7502fa5b03997eb77
Signing key:
Tree: 61228e47034a7660ef2a0f4a379b78cc859b75e3
File Lines added Lines deleted
src/hstr.c 7 7
src/hstr_curses.c 11 1
src/include/hstr_curses.h 2 1
tests/bin/hh-env-monster.sh 0 0
tests/bin/hh-env-utf8.sh 5 0
tests/resources/.bash_history_cz 2 0
tests/src/test_keyb.c 2 1
tests/src/test_utf8.c 39 4
tests/test_utf8.sh 8 0
File src/hstr.c changed (mode: 100644) (index 398a862..c9f90bf)
12 12 #include <curses.h> #include <curses.h>
13 13 #include <getopt.h> #include <getopt.h>
14 14 #include <regex.h> #include <regex.h>
15 #include <locale.h>
15 16 #include <signal.h> #include <signal.h>
16 17 #include <stdbool.h> #include <stdbool.h>
17 18 #include <stddef.h> #include <stddef.h>
 
... ... static const char *HELP_STRING=
148 149 "\n"; "\n";
149 150
150 151 static const char *VERSION_STRING= static const char *VERSION_STRING=
151 "hh version \"1.12\""
152 "hh version \"1.13\""
152 153 "\n build \""__DATE__" " __TIME__"\"" "\n build \""__DATE__" " __TIME__"\""
153 154 "\n"; "\n";
154 155
 
... ... void hstr_on_exit(Hstr *hstr)
649 650 void signal_callback_handler_ctrl_c(int signum) void signal_callback_handler_ctrl_c(int signum)
650 651 { {
651 652 if(signum==SIGINT) { if(signum==SIGINT) {
652 endwin();
653 hstr_curses_stop();
653 654 hstr_on_exit(hstr); hstr_on_exit(hstr);
654 655 exit(signum); exit(signum);
655 656 } }
 
... ... void loop_to_select(Hstr *hstr)
684 685 { {
685 686 signal(SIGINT, signal_callback_handler_ctrl_c); signal(SIGINT, signal_callback_handler_ctrl_c);
686 687
687 initscr();
688 keypad(stdscr, TRUE);
689 noecho();
690 color_start();
688 hstr_curses_start();
691 689 // TODO move the code below to hstr_curses // TODO move the code below to hstr_curses
692 690 color_init_pair(HH_COLOR_NORMAL, -1, -1); color_init_pair(HH_COLOR_NORMAL, -1, -1);
693 691 if(hstr->hicolor) { if(hstr->hicolor) {
 
... ... void loop_to_select(Hstr *hstr)
923 921 break; break;
924 922 } }
925 923 } }
926 endwin();
924 hstr_curses_stop();
927 925
928 926 if(result!=NULL) { if(result!=NULL) {
929 927 fill_terminal_input(result, TRUE); fill_terminal_input(result, TRUE);
 
... ... void hstr_getopt(int argc, char **argv, Hstr *hstr)
1015 1013
1016 1014 int main(int argc, char *argv[]) int main(int argc, char *argv[])
1017 1015 { {
1016 setlocale(LC_ALL, "");
1017
1018 1018 hstr=malloc(sizeof(Hstr)); hstr=malloc(sizeof(Hstr));
1019 1019
1020 1020 hstr_init(hstr); hstr_init(hstr);
File src/hstr_curses.c changed (mode: 100644) (index 0b765e7..4840406)
12 12
13 13 static bool terminalHasColors=FALSE; static bool terminalHasColors=FALSE;
14 14
15 void color_start()
15 void hstr_curses_start()
16 16 { {
17 initscr();
18 keypad(stdscr, TRUE);
19 noecho();
17 20 terminalHasColors=has_colors(); terminalHasColors=has_colors();
18 21 if(terminalHasColors) { if(terminalHasColors) {
19 22 start_color(); start_color();
 
... ... void color_start()
24 27 bool terminal_has_colors() { bool terminal_has_colors() {
25 28 return terminalHasColors; return terminalHasColors;
26 29 } }
30
31 void hstr_curses_stop() {
32 clear();
33 refresh();
34 doupdate();
35 endwin();
36 }
File src/include/hstr_curses.h changed (mode: 100644) (index 28851d5..b98eb7b)
16 16 #define color_attr_off(C) if(terminal_has_colors()) { attroff(C); } #define color_attr_off(C) if(terminal_has_colors()) { attroff(C); }
17 17 #define color_init_pair(X, Y, Z) if(terminal_has_colors()) { init_pair(X, Y, Z); } #define color_init_pair(X, Y, Z) if(terminal_has_colors()) { init_pair(X, Y, Z); }
18 18
19 void hstr_curses_start();
19 20 bool terminal_has_colors(); bool terminal_has_colors();
20 void color_start();
21 void hstr_curses_stop();
21 22
22 23 #endif #endif
File tests/bin/hh-env-monster.sh renamed from tests/bin/monster-hh-env.sh (similarity 100%)
File tests/bin/hh-env-utf8.sh added (mode: 100755) (index 0000000..9d4976a)
1 #!/bin/bash
2
3 export HISTFILE=/home/dvorka/p/hstr/github/tests/resources/.bash_history_cz
4
5 # eof
File tests/resources/.bash_history_cz added (mode: 100644) (index 0000000..a2adbb9)
1 ěščřžýáíé
2 ŘŠČŽ
File tests/src/test_keyb.c changed (mode: 100644) (index c49f7e5..1e309cd)
... ... void echo_printable_characters()
22 22 } }
23 23 } }
24 24
25 void echo_keyb_characters() {
25 void echo_keyb_characters()
26 {
26 27 int c; int c;
27 28 while(1) { while(1) {
28 29 c = getc(stdin); c = getc(stdin);
File tests/src/test_utf8.c changed (mode: 100644) (index 551eb8b..1303adb)
7 7 ============================================================================ ============================================================================
8 8 */ */
9 9
10 #include <string.h>
10 #include <locale.h>
11 #include <wchar.h>
11 12 #include <stdio.h> #include <stdio.h>
13 #include <readline/readline.h>
14 #include <readline/chardefs.h>
15
16 void echo_czech()
17 {
18 int c;
19 while(1) {
20 c = getc(stdin);
21 printf("\nKey: '%3d', char: '%c'", c, c);
22 }
23 }
24
25 void static_wide_czech()
26 {
27 setlocale(LC_ALL, "");
28
29 wchar_t *w=L"Čeština.";
30 wprintf(L"\nStatic wprintf: %ls", w);
31 }
32
33 void static_czech()
34 {
35 setlocale(LC_ALL, "");
36
37 char *s="Čeština ěščřžýáíé.";
38 printf("\nStatic printf: %s", s);
39 }
40
41 void check()
42 {
43 printf("\nEnglish string.");
44 }
12 45
13 #define LINELNG 500
14 46
15 47 int main(int argc, char *argv[]) int main(int argc, char *argv[])
16 48 { {
17 // UTF8 test: czech & chinese
18 // hf @ SF.net as inspiration
49 check();
50 static_czech();
51 static_wide_czech();
52 echo_czech();
53 printf("\n\n");
19 54 } }
File tests/test_utf8.sh added (mode: 100755) (index 0000000..b0a9578)
1 #!/bin/bash
2
3 clear
4 gcc ./src/test_utf8.c -o _utf8
5 ./_utf8
6
7 # eof
8
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/hstr

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/hstr

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master