|
@@ -358,7 +358,6 @@ static bool_t tinyrl_key_escape(tinyrl_t * this, int key)
|
|
|
case tinyrl_vt100_DELETE:
|
|
|
result = tinyrl_key_delete(this,key);
|
|
|
break;
|
|
|
-
|
|
|
case tinyrl_vt100_INSERT:
|
|
|
case tinyrl_vt100_PGDOWN:
|
|
|
case tinyrl_vt100_PGUP:
|
|
@@ -506,7 +505,7 @@ int tinyrl_getchar(const tinyrl_t * this)
|
|
|
|
|
|
static void tinyrl_internal_print(const tinyrl_t * this, const char *text)
|
|
|
{
|
|
|
- if (BOOL_TRUE == this->echo_enabled) {
|
|
|
+ if (this->echo_enabled) {
|
|
|
|
|
|
tinyrl_vt100_printf(this->term, "%s", text);
|
|
|
} else {
|
|
@@ -521,129 +520,58 @@ static void tinyrl_internal_print(const tinyrl_t * this, const char *text)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+static void tinyrl_internal_position(tinyrl_t *this, size_t prompt_len,
|
|
|
+ size_t line_len, unsigned int width)
|
|
|
+{
|
|
|
+ int rows, cols;
|
|
|
+
|
|
|
+ rows = ((line_len + prompt_len) / width) - (prompt_len / width);
|
|
|
+ cols = ((line_len + prompt_len) % width) - (prompt_len % width);
|
|
|
+ if (cols > 0)
|
|
|
+ tinyrl_vt100_cursor_back(this->term, cols);
|
|
|
+ else if (cols < 0)
|
|
|
+ tinyrl_vt100_cursor_forward(this->term, -cols);
|
|
|
+ if (rows > 0)
|
|
|
+ tinyrl_vt100_cursor_up(this->term, rows);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
void tinyrl_redisplay(tinyrl_t * this)
|
|
|
{
|
|
|
- int delta;
|
|
|
- unsigned line_len, last_line_len, count;
|
|
|
- line_len = strlen(this->line);
|
|
|
- last_line_len = (this->last_buffer ? strlen(this->last_buffer) : 0);
|
|
|
-
|
|
|
- do {
|
|
|
- if (this->last_buffer) {
|
|
|
- delta = (int)(line_len - last_line_len);
|
|
|
- if (delta > 0) {
|
|
|
- count = (unsigned)delta;
|
|
|
-
|
|
|
- if (0 == strncmp(this->line, this->last_buffer,
|
|
|
- last_line_len)) {
|
|
|
-
|
|
|
- tinyrl_internal_print(this,
|
|
|
- &this->line[line_len - count]);
|
|
|
- break;
|
|
|
- }
|
|
|
- } else if (delta < 0) {
|
|
|
-
|
|
|
- if (0 == strncmp(this->line, this->last_buffer,
|
|
|
- line_len)) {
|
|
|
- if (this->echo_enabled
|
|
|
- || this->echo_char) {
|
|
|
- int shift = (int)(this->last_point -
|
|
|
- this->point);
|
|
|
-
|
|
|
- if (shift > 0) {
|
|
|
- count = utf8_nsyms(this,
|
|
|
- this->last_buffer + this->point,
|
|
|
- (unsigned)shift);
|
|
|
-
|
|
|
- tinyrl_vt100_cursor_back
|
|
|
- (this->term, count);
|
|
|
- } else if (shift < 0) {
|
|
|
- count = utf8_nsyms(this,
|
|
|
- this->last_buffer + this->last_point,
|
|
|
- (unsigned)-shift);
|
|
|
-
|
|
|
- tinyrl_vt100_cursor_forward
|
|
|
- (this->term, count);
|
|
|
- }
|
|
|
-
|
|
|
- count = utf8_nsyms(this,
|
|
|
- this->last_buffer + line_len,
|
|
|
- (unsigned)-delta);
|
|
|
- tinyrl_vt100_erase(this->term,
|
|
|
- count);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- if (0 == strcmp(this->line, this->last_buffer)) {
|
|
|
- if (this->echo_enabled
|
|
|
- || this->echo_char) {
|
|
|
- delta =
|
|
|
- (int)(this->point -
|
|
|
- this->last_point);
|
|
|
- if (delta > 0) {
|
|
|
- count = utf8_nsyms(this,
|
|
|
- this->line + this->last_point,
|
|
|
- (unsigned)delta);
|
|
|
-
|
|
|
- tinyrl_vt100_cursor_forward
|
|
|
- (this->term, count);
|
|
|
- } else if (delta < 0) {
|
|
|
- count = utf8_nsyms(this,
|
|
|
- this->line + this->point,
|
|
|
- (unsigned)-delta);
|
|
|
-
|
|
|
- tinyrl_vt100_cursor_back
|
|
|
- (this->term, count);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- tinyrl_vt100_printf(this->term, "%s", this->prompt);
|
|
|
- tinyrl_internal_print(this, this->line);
|
|
|
- if (this->point < line_len) {
|
|
|
-
|
|
|
- count = utf8_nsyms(this,
|
|
|
- this->line + this->point,
|
|
|
- line_len - this->point);
|
|
|
- tinyrl_vt100_cursor_back(this->term, count);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- * to have got this far we must have edited the middle of a line.
|
|
|
- */
|
|
|
- if (this->last_point) {
|
|
|
-
|
|
|
- count = utf8_nsyms(this, this->last_buffer, this->last_point);
|
|
|
- tinyrl_vt100_cursor_back(this->term, count);
|
|
|
- }
|
|
|
-
|
|
|
- count = utf8_nsyms(this, this->last_buffer, last_line_len);
|
|
|
- tinyrl_vt100_erase(this->term, count);
|
|
|
-
|
|
|
-
|
|
|
- tinyrl_internal_print(this, this->line);
|
|
|
-
|
|
|
- delta = (int)(line_len - this->point);
|
|
|
- if (delta) {
|
|
|
-
|
|
|
- count = utf8_nsyms(this, this->line + this->point, delta);
|
|
|
- tinyrl_vt100_cursor_back(this->term, count);
|
|
|
- }
|
|
|
- } while (0)
|
|
|
- ;
|
|
|
+ unsigned int count;
|
|
|
+ unsigned int line_size = strlen(this->line);
|
|
|
+ unsigned int line_len = utf8_nsyms(this, this->line, line_size);
|
|
|
+ unsigned int width = tinyrl_vt100__get_width(this->term);
|
|
|
+ int cols;
|
|
|
+
|
|
|
+
|
|
|
+ if (this->last_buffer) {
|
|
|
+ count = utf8_nsyms(this, this->last_buffer, this->last_point);
|
|
|
+ tinyrl_internal_position(this, this->prompt_len, count, width);
|
|
|
+ tinyrl_vt100_erase_down(this->term);
|
|
|
+ } else
|
|
|
+ tinyrl_vt100_printf(this->term, "%s", this->prompt);
|
|
|
+
|
|
|
+
|
|
|
+ tinyrl_internal_print(this, this->line);
|
|
|
+
|
|
|
+ cols = (this->prompt_len + line_len) % width;
|
|
|
+ if (!cols && line_size)
|
|
|
+ tinyrl_vt100_next_line(this->term);
|
|
|
+ if (this->point < line_size) {
|
|
|
+ unsigned int pre_len = utf8_nsyms(this,
|
|
|
+ this->line, this->point);
|
|
|
+ count = utf8_nsyms(this, this->line + this->point,
|
|
|
+ line_size - this->point);
|
|
|
+ tinyrl_internal_position(this, this->prompt_len + pre_len,
|
|
|
+ count, width);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
+
|
|
|
(void)tinyrl_vt100_oflush(this->term);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
lub_string_free(this->last_buffer);
|
|
|
this->last_buffer = lub_string_dup(this->line);
|
|
|
this->last_point = this->point;
|
|
@@ -1327,10 +1255,14 @@ void tinyrl__set_prompt(tinyrl_t *this, const char *prompt)
|
|
|
if (this->prompt) {
|
|
|
lub_string_free(this->prompt);
|
|
|
this->prompt_size = 0;
|
|
|
+ this->prompt_len = 0;
|
|
|
}
|
|
|
this->prompt = lub_string_dup(prompt);
|
|
|
- if (this->prompt)
|
|
|
+ if (this->prompt) {
|
|
|
this->prompt_size = strlen(this->prompt);
|
|
|
+ this->prompt_len = utf8_nsyms(this, this->prompt,
|
|
|
+ this->prompt_size);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|