mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Merge branch 'master' into build
This commit is contained in:
commit
302978fe8a
115
src/input_win.c
115
src/input_win.c
@ -30,10 +30,13 @@
|
|||||||
* The example below shows the values of size, input, a call to wgetyx to
|
* The example below shows the values of size, input, a call to wgetyx to
|
||||||
* find the current cursor location, and the index of the input string.
|
* find the current cursor location, and the index of the input string.
|
||||||
*
|
*
|
||||||
* size : " 7 "
|
* view : |mple|
|
||||||
* input : " example "
|
* input : "example te"
|
||||||
* inp_x : "012345678"
|
* index : "0123456789"
|
||||||
* index : " 0123456 " (inp_x - 1)
|
* inp_x : "0123456789"
|
||||||
|
* size : 10
|
||||||
|
* pad_start : 3
|
||||||
|
* cols : 4
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -48,6 +51,8 @@
|
|||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
||||||
static WINDOW *inp_win;
|
static WINDOW *inp_win;
|
||||||
|
static int MAX_INP_SIZE = 1000;
|
||||||
|
static int pad_start = 0;
|
||||||
|
|
||||||
static int _handle_edit(const int ch, char *input, int *size);
|
static int _handle_edit(const int ch, char *input, int *size);
|
||||||
static int _printable(const int ch);
|
static int _printable(const int ch);
|
||||||
@ -58,28 +63,35 @@ void create_input_window(void)
|
|||||||
int rows, cols;
|
int rows, cols;
|
||||||
getmaxyx(stdscr, rows, cols);
|
getmaxyx(stdscr, rows, cols);
|
||||||
|
|
||||||
inp_win = newwin(1, cols, rows-1, 0);
|
inp_win = newpad(1, MAX_INP_SIZE);
|
||||||
wbkgd(inp_win, COLOR_PAIR(1));
|
wbkgd(inp_win, COLOR_PAIR(1));
|
||||||
keypad(inp_win, TRUE);
|
keypad(inp_win, TRUE);
|
||||||
// wattrset(inp_win, A_BOLD);
|
wmove(inp_win, 0, 0);
|
||||||
wmove(inp_win, 0, 1);
|
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
|
||||||
wrefresh(inp_win);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void inp_win_resize(const char * const input, const int size)
|
void inp_win_resize(const char * const input, const int size)
|
||||||
{
|
{
|
||||||
int rows, cols;
|
int rows, cols, inp_x, inp_y;
|
||||||
getmaxyx(stdscr, rows, cols);
|
getmaxyx(stdscr, rows, cols);
|
||||||
mvwin(inp_win, rows-1, 0);
|
getyx(inp_win, inp_y, inp_x);
|
||||||
wresize(inp_win, 1, cols);
|
|
||||||
wrefresh(inp_win);
|
// if lost cursor off screen, move contents to show it
|
||||||
|
if (inp_x >= pad_start + cols) {
|
||||||
|
pad_start = inp_x - 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
prefresh(inp_win, pad_start, 0, rows-1, 0, rows-1, cols-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inp_clear(void)
|
void inp_clear(void)
|
||||||
{
|
{
|
||||||
|
int rows, cols;
|
||||||
|
getmaxyx(stdscr, rows, cols);
|
||||||
wclear(inp_win);
|
wclear(inp_win);
|
||||||
wmove(inp_win, 0, 1);
|
wmove(inp_win, 0, 0);
|
||||||
wrefresh(inp_win);
|
pad_start = 0;
|
||||||
|
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inp_non_block(void)
|
void inp_non_block(void)
|
||||||
@ -97,9 +109,8 @@ void inp_get_char(int *ch, char *input, int *size)
|
|||||||
int inp_y = 0;
|
int inp_y = 0;
|
||||||
int inp_x = 0;
|
int inp_x = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
||||||
// echo off, and get some more input
|
// echo off, and get some more input
|
||||||
noecho();
|
noecho();
|
||||||
*ch = wgetch(inp_win);
|
*ch = wgetch(inp_win);
|
||||||
|
|
||||||
@ -109,13 +120,13 @@ void inp_get_char(int *ch, char *input, int *size)
|
|||||||
getyx(inp_win, inp_y, inp_x);
|
getyx(inp_win, inp_y, inp_x);
|
||||||
|
|
||||||
// handle insert if not at end of input
|
// handle insert if not at end of input
|
||||||
if (inp_x <= *size) {
|
if (inp_x < *size) {
|
||||||
winsch(inp_win, *ch);
|
winsch(inp_win, *ch);
|
||||||
wmove(inp_win, inp_y, inp_x+1);
|
wmove(inp_win, inp_y, inp_x+1);
|
||||||
|
|
||||||
for (i = *size; i > inp_x -1; i--)
|
for (i = *size; i > inp_x; i--)
|
||||||
input[i] = input[i-1];
|
input[i] = input[i-1];
|
||||||
input[inp_x -1] = *ch;
|
input[inp_x] = *ch;
|
||||||
|
|
||||||
(*size)++;
|
(*size)++;
|
||||||
|
|
||||||
@ -123,6 +134,14 @@ void inp_get_char(int *ch, char *input, int *size)
|
|||||||
} else {
|
} else {
|
||||||
waddch(inp_win, *ch);
|
waddch(inp_win, *ch);
|
||||||
input[(*size)++] = *ch;
|
input[(*size)++] = *ch;
|
||||||
|
|
||||||
|
// if gone over screen size follow input
|
||||||
|
int rows, cols;
|
||||||
|
getmaxyx(stdscr, rows, cols);
|
||||||
|
if (*size - pad_start > cols-2) {
|
||||||
|
pad_start++;
|
||||||
|
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_search_attempts();
|
reset_search_attempts();
|
||||||
@ -139,14 +158,16 @@ void inp_get_password(char *passwd)
|
|||||||
wclear(inp_win);
|
wclear(inp_win);
|
||||||
noecho();
|
noecho();
|
||||||
mvwgetnstr(inp_win, 0, 1, passwd, 20);
|
mvwgetnstr(inp_win, 0, 1, passwd, 20);
|
||||||
wmove(inp_win, 0, 1);
|
wmove(inp_win, 0, 0);
|
||||||
echo();
|
echo();
|
||||||
status_bar_clear();
|
status_bar_clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void inp_put_back(void)
|
void inp_put_back(void)
|
||||||
{
|
{
|
||||||
wrefresh(inp_win);
|
int rows, cols;
|
||||||
|
getmaxyx(stdscr, rows, cols);
|
||||||
|
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -156,7 +177,7 @@ void inp_put_back(void)
|
|||||||
*/
|
*/
|
||||||
static int _handle_edit(const int ch, char *input, int *size)
|
static int _handle_edit(const int ch, char *input, int *size)
|
||||||
{
|
{
|
||||||
int i;
|
int i, rows, cols;
|
||||||
char *prev = NULL;
|
char *prev = NULL;
|
||||||
char *next = NULL;
|
char *next = NULL;
|
||||||
char *found = NULL;
|
char *found = NULL;
|
||||||
@ -165,6 +186,7 @@ static int _handle_edit(const int ch, char *input, int *size)
|
|||||||
int inp_x = 0;
|
int inp_x = 0;
|
||||||
char inp_cpy[*size];
|
char inp_cpy[*size];
|
||||||
|
|
||||||
|
getmaxyx(stdscr, rows, cols);
|
||||||
getyx(inp_win, inp_y, inp_x);
|
getyx(inp_win, inp_y, inp_x);
|
||||||
|
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
@ -175,14 +197,14 @@ static int _handle_edit(const int ch, char *input, int *size)
|
|||||||
if (*size > 0) {
|
if (*size > 0) {
|
||||||
|
|
||||||
// if at end, delete last char
|
// if at end, delete last char
|
||||||
if (inp_x > *size) {
|
if (inp_x >= *size) {
|
||||||
wmove(inp_win, inp_y, inp_x-1);
|
wmove(inp_win, inp_y, inp_x-1);
|
||||||
wdelch(inp_win);
|
wdelch(inp_win);
|
||||||
(*size)--;
|
(*size)--;
|
||||||
|
|
||||||
// if in middle, delete and shift chars left
|
// if in middle, delete and shift chars left
|
||||||
} else if (inp_x > 1 && inp_x <= *size) {
|
} else if (inp_x > 0 && inp_x < *size) {
|
||||||
for (i = inp_x-1; i < *size; i++)
|
for (i = inp_x; i < *size; i++)
|
||||||
input[i-1] = input[i];
|
input[i-1] = input[i];
|
||||||
(*size)--;
|
(*size)--;
|
||||||
|
|
||||||
@ -195,12 +217,12 @@ static int _handle_edit(const int ch, char *input, int *size)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case KEY_DC: // DEL
|
case KEY_DC: // DEL
|
||||||
if (inp_x <= *size) {
|
if (inp_x < *size) {
|
||||||
wdelch(inp_win);
|
wdelch(inp_win);
|
||||||
|
|
||||||
// if not last char, shift chars left
|
// if not last char, shift chars left
|
||||||
if (inp_x < *size)
|
if (inp_x < *size - 1)
|
||||||
for (i = inp_x-1; i < *size; i++)
|
for (i = inp_x; i < *size; i++)
|
||||||
input[i] = input[i+1];
|
input[i] = input[i+1];
|
||||||
|
|
||||||
(*size)--;
|
(*size)--;
|
||||||
@ -208,33 +230,58 @@ static int _handle_edit(const int ch, char *input, int *size)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case KEY_LEFT:
|
case KEY_LEFT:
|
||||||
if (inp_x > 1)
|
if (inp_x > 0)
|
||||||
wmove(inp_win, inp_y, inp_x-1);
|
wmove(inp_win, inp_y, inp_x-1);
|
||||||
|
|
||||||
|
// current position off screen to left
|
||||||
|
if (inp_x - 1 < pad_start) {
|
||||||
|
pad_start--;
|
||||||
|
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case KEY_RIGHT:
|
case KEY_RIGHT:
|
||||||
if (inp_x <= *size )
|
if (inp_x < *size) {
|
||||||
wmove(inp_win, inp_y, inp_x+1);
|
wmove(inp_win, inp_y, inp_x+1);
|
||||||
|
|
||||||
|
// current position off screen to right
|
||||||
|
if ((inp_x + 1 - pad_start) >= cols) {
|
||||||
|
pad_start++;
|
||||||
|
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
prev = history_previous(input, size);
|
prev = history_previous(input, size);
|
||||||
if (prev)
|
if (prev) {
|
||||||
_replace_input(input, prev, size);
|
_replace_input(input, prev, size);
|
||||||
|
pad_start = 0;
|
||||||
|
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
next = history_next(input, size);
|
next = history_next(input, size);
|
||||||
if (next)
|
if (next) {
|
||||||
_replace_input(input, next, size);
|
_replace_input(input, next, size);
|
||||||
|
pad_start = 0;
|
||||||
|
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case KEY_HOME:
|
case KEY_HOME:
|
||||||
wmove(inp_win, inp_y, 1);
|
wmove(inp_win, inp_y, 0);
|
||||||
|
pad_start = 0;
|
||||||
|
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case KEY_END:
|
case KEY_END:
|
||||||
wmove(inp_win, inp_y, (*size) + 1);
|
wmove(inp_win, inp_y, *size);
|
||||||
|
if (*size > cols-2) {
|
||||||
|
pad_start = *size - cols + 1;
|
||||||
|
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case 9: // tab
|
case 9: // tab
|
||||||
|
Loading…
Reference in New Issue
Block a user