X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/742961730553cdf21649744cc212d309a56bd0f0..d428e0289e70ff5725f7b606ce1a69bd96e110d3:/Display.cpp diff --git a/Display.cpp b/Display.cpp index 56cbb5e..555bd6d 100644 --- a/Display.cpp +++ b/Display.cpp @@ -40,14 +40,6 @@ CYCursor current_; int width_; size_t point_; -const char *CYDisplayPrompt() { -#if RL_READLINE_VERSION >= 0x0600 - return rl_display_prompt; -#else - return rl_prompt; -#endif -} - unsigned CYDisplayWidth() { struct winsize info; if (ioctl(1, TIOCGWINSZ, &info) != -1) @@ -80,36 +72,40 @@ CYCursor CYDisplayOutput(int (*put)(int), int width, const char *data, ssize_t o case CYIgnoreStart: CYDisplayOutput_(put, data); - ++offset; - break; - case CYIgnoreEnd: ++offset; break; default: - if (put != NULL) - put(next); - current_ += CYCursor(0, 1); if (current_.imag() == width) + case '\n': current_ = CYCursor(current_.real() + 1, 0); + if (put != NULL) + put(next); break; + } } +} - return point; +void CYDisplayMove_(char *negative, char *positive, int offset) { + if (offset < 0) + putp(tparm(negative, -offset)); + else if (offset > 0) + putp(tparm(positive, offset)); } void CYDisplayMove(CYCursor target) { - int offset(target.real() - current_.real()); + CYCursor offset(target - current_); - if (offset < 0) - putp(tparm(parm_up_cursor, -offset)); - else if (offset > 0) - putp(tparm(parm_down_cursor, offset)); + CYDisplayMove_(parm_up_cursor, parm_down_cursor, offset.real()); + + if (char *parm = tparm(column_address, target.imag())) + putp(parm); + else + CYDisplayMove_(parm_left_cursor, parm_right_cursor, offset.imag()); - putp(tparm(column_address, target.imag())); current_ = target; } @@ -119,6 +115,12 @@ void CYDisplayStart(int meta) { } void CYDisplayUpdate() { +#if RL_READLINE_VERSION >= 0x0600 + const char *prompt(rl_display_prompt); +#else + const char *prompt(rl_prompt); +#endif + std::ostringstream stream; CYLexerHighlight(rl_line_buffer, rl_end, stream, true); std::string string(stream.str()); @@ -127,12 +129,12 @@ void CYDisplayUpdate() { int width(CYDisplayWidth()); if (width_ != width) { current_ = CYCursor(); - CYDisplayOutput(NULL, width, CYDisplayPrompt()); - CYDisplayOutput(NULL, width, buffer, point_); + CYDisplayOutput(NULL, width, prompt); + current_ = CYDisplayOutput(NULL, width, buffer, point_); } CYDisplayMove(CYCursor()); - CYDisplayOutput(putchar, width, CYDisplayPrompt()); + CYDisplayOutput(putchar, width, prompt); CYCursor target(CYDisplayOutput(putchar, width, stream.str().c_str(), rl_point)); if (target.imag() == 0)