X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/7128e55c56fe8b4a61c8537f5814cadedcb747dc..e66ced89a433143539ae398bf21c1e74993db5fa:/Display.cpp diff --git a/Display.cpp b/Display.cpp index adfabdb..5227fa1 100644 --- a/Display.cpp +++ b/Display.cpp @@ -1,21 +1,21 @@ /* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2012 Jay Freeman (saurik) + * Copyright (C) 2009-2015 Jay Freeman (saurik) */ -/* GNU Lesser General Public License, Version 3 {{{ */ +/* GNU Affero General Public License, Version 3 {{{ */ /* - * Cycript is free software: you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * Cycript is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Cycript. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . **/ /* }}} */ @@ -28,14 +28,21 @@ #include #endif -#include +#if RL_READLINE_VERSION >= 0x0600 -#include "Highlight.hpp" +#include #include +#include "Highlight.hpp" + typedef std::complex CYCursor; +extern "C" int rl_display_fixed; +extern "C" int _rl_vis_botlin; +extern "C" int _rl_last_c_pos; +extern "C" int _rl_last_v_pos; + CYCursor current_; int width_; size_t point_; @@ -72,45 +79,48 @@ 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()); - putp(tparm(column_address, target.imag())); - current_ = target; -} + if (char *parm = tparm(column_address, target.imag())) + putp(parm); + else + CYDisplayMove_(parm_left_cursor, parm_right_cursor, offset.imag()); -void CYDisplayStart(int meta) { - rl_prep_terminal(meta); - current_ = CYCursor(); + current_ = target; } void CYDisplayUpdate() { + rl_display_fixed = 1; + rl_redisplay(); + current_ = CYCursor(_rl_last_v_pos, _rl_last_c_pos); + #if RL_READLINE_VERSION >= 0x0600 const char *prompt(rl_display_prompt); #else @@ -126,25 +136,27 @@ void CYDisplayUpdate() { if (width_ != width) { current_ = CYCursor(); CYDisplayOutput(NULL, width, prompt); - CYDisplayOutput(NULL, width, buffer, point_); + current_ = CYDisplayOutput(NULL, width, buffer, point_); } CYDisplayMove(CYCursor()); CYDisplayOutput(putchar, width, prompt); - CYCursor target(CYDisplayOutput(putchar, width, stream.str().c_str(), rl_point)); - if (target.imag() == 0) - putp(cursor_down); + _rl_vis_botlin = current_.real(); + + if (current_.imag() == 0) + CYDisplayOutput(putchar, width, " "); putp(clr_eos); - CYDisplayMove(target); + CYDisplayMove(target); fflush(stdout); + _rl_last_v_pos = current_.real(); + _rl_last_c_pos = current_.imag(); + width_ = width; point_ = rl_point; } -void CYDisplayFinish() { - rl_deprep_terminal(); -} +#endif