xaizek / pms (License: GPLv3+) (since 2018-12-07)
Older version of Practical Music Search written in C++.
Commit 6ca195c0e2246e4c70fb2e41e056d2f7a8bc1299

Implement scroll to beginning and end of console.
Author: Kim Tore Jensen
Author date (UTC): 2014-09-28 14:25
Committer name: Kim Tore Jensen
Committer date (UTC): 2014-09-28 14:25
Parent(s): 86c4c604589bbe3e5f2cbb19e0a96a6a4cb6a29f
Signing key:
Tree: c3357dea8b867b9ce41f4dae8b57b4536ec8e247
File Lines added Lines deleted
src/console.c 8 0
src/console.h 7 0
src/input.c 18 2
src/input.h 3 2
File src/console.c changed (mode: 100644) (index 5575a12..3431e0b)
... ... int console_scroll(long delta) {
135 135 return changed; return changed;
136 136 } }
137 137
138 int console_scroll_to(long position) {
139 if (position < 0) {
140 position = console_window->num_lines+position;
141 }
142 position -= console_window->position;
143 console_scroll(position);
144 }
145
138 146 logline_t * new_logline() { logline_t * new_logline() {
139 147 logline_t * line; logline_t * line;
140 148
File src/console.h changed (mode: 100644) (index 8ffed34..87f4645)
... ... void console_draw_lines(long start, long end);
54 54 */ */
55 55 int console_scroll(long delta); int console_scroll(long delta);
56 56
57 /**
58 * Scroll console to an absolute position.
59 *
60 * @see window_scroll@window.h
61 */
62 int console_scroll_to(long position);
63
57 64 /** /**
58 65 * Allocate memory for a log line. * Allocate memory for a log line.
59 66 */ */
File src/input.c changed (mode: 100644) (index 13f48ba..f8a99aa)
... ... static int input_char_get_movement(int ch) {
35 35 return INPUT_MOVEMENT_UP; return INPUT_MOVEMENT_UP;
36 36 } else if (ch == KEY_DOWN || ch == 'j') { } else if (ch == KEY_DOWN || ch == 'j') {
37 37 return INPUT_MOVEMENT_DOWN; return INPUT_MOVEMENT_DOWN;
38 } else if (ch == 'G') {
39 return INPUT_MOVEMENT_END;
38 40 } }
39 41 return INPUT_MOVEMENT_NONE; return INPUT_MOVEMENT_NONE;
40 42 } }
 
... ... static int input_char_get_action(int ch) {
46 48 return INPUT_ACTION_GO; return INPUT_ACTION_GO;
47 49 } else if (ch == 'q') { } else if (ch == 'q') {
48 50 return INPUT_ACTION_QUIT; return INPUT_ACTION_QUIT;
49 } else if (ch == 'g') {
51 } else if (ch == 'g' || ch == 'G') {
50 52 return INPUT_ACTION_GO; return INPUT_ACTION_GO;
51 53 } }
52 54 return INPUT_ACTION_NONE; return INPUT_ACTION_NONE;
 
... ... command_t * input_get() {
95 97 input_command_append_movement(i); input_command_append_movement(i);
96 98 } }
97 99 if ((i = input_char_get_action(ch)) != INPUT_ACTION_NONE) { if ((i = input_char_get_action(ch)) != INPUT_ACTION_NONE) {
98 input_command_append_action(i);
100 if (command.action != INPUT_ACTION_NONE && command.action != i) {
101 console("Invalid input sequence, resetting.");
102 input_reset();
103 }
104 if (command.action == INPUT_ACTION_NONE) {
105 input_command_append_action(i);
106 } else if (command.movement == INPUT_MOVEMENT_NONE) {
107 input_command_append_movement(INPUT_MOVEMENT_NA);
108 }
99 109 } }
100 110 if (input_ready()) { if (input_ready()) {
101 111 if (command.multiplier == 0) { if (command.multiplier == 0) {
 
... ... int input_handle(command_t * command) {
116 126 console_scroll(-command->multiplier); console_scroll(-command->multiplier);
117 127 } else if (command->movement == INPUT_MOVEMENT_DOWN) { } else if (command->movement == INPUT_MOVEMENT_DOWN) {
118 128 console_scroll(command->multiplier); console_scroll(command->multiplier);
129 } else if (command->movement == INPUT_MOVEMENT_END) {
130 console_scroll_to(-1);
131 return 0;
132 } else if (command->movement == INPUT_MOVEMENT_NA) {
133 console_scroll_to(command->multiplier-1); // convert 1-indexed to 0-indexed
134 return 0;
119 135 } }
120 136 } else { } else {
121 137 return 0; return 0;
File src/input.h changed (mode: 100644) (index cbd3212..bb02bd8)
17 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18 */ */
19 19
20 #define INPUT_MOVEMENT_NA -1
20 #define INPUT_MOVEMENT_NA -1
21 21 #define INPUT_MOVEMENT_NONE 0 #define INPUT_MOVEMENT_NONE 0
22 #define INPUT_MOVEMENT_UP 1
22 #define INPUT_MOVEMENT_UP 1
23 23 #define INPUT_MOVEMENT_DOWN 2 #define INPUT_MOVEMENT_DOWN 2
24 #define INPUT_MOVEMENT_END 3
24 25
25 26 #define INPUT_ACTION_NONE 0 #define INPUT_ACTION_NONE 0
26 27 #define INPUT_ACTION_QUIT 1 #define INPUT_ACTION_QUIT 1
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/pms

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

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