]>
git.saurik.com Git - cycript.git/blob - Display.cpp
adfabdb4c0d307a6cf1e3c0e8b55c013cd13fda3
   1 /* Cycript - Optimizing JavaScript Compiler/Runtime 
   2  * Copyright (C) 2009-2012  Jay Freeman (saurik) 
   5 /* GNU Lesser General Public License, Version 3 {{{ */ 
   7  * Cycript is free software: you can redistribute it and/or modify it under 
   8  * the terms of the GNU Lesser General Public License as published by the 
   9  * Free Software Foundation, either version 3 of the License, or (at your 
  10  * option) any later version. 
  12  * Cycript is distributed in the hope that it will be useful, but WITHOUT 
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
  15  * License for more details. 
  17  * You should have received a copy of the GNU Lesser General Public License 
  18  * along with Cycript.  If not, see <http://www.gnu.org/licenses/>. 
  25 #ifdef HAVE_READLINE_H 
  28 #include <readline/readline.h> 
  31 #include <sys/ioctl.h> 
  33 #include "Highlight.hpp" 
  37 typedef std::complex<int> CYCursor
; 
  43 unsigned CYDisplayWidth() { 
  45     if (ioctl(1, TIOCGWINSZ
, &info
) != -1) 
  47     return tgetnum(const_cast<char *>("co")); 
  50 void CYDisplayOutput_(int (*put
)(int), const char *&data
) { 
  53         if (next 
== '\0' || next 
== CYIgnoreEnd
) 
  60 CYCursor 
CYDisplayOutput(int (*put
)(int), int width
, const char *data
, ssize_t offset 
= 0) { 
  61     CYCursor 
point(current_
); 
  74                 CYDisplayOutput_(put
, data
); 
  86                 current_ 
+= CYCursor(0, 1); 
  87                 if (current_
.imag() == width
) 
  88                     current_ 
= CYCursor(current_
.real() + 1, 0); 
  96 void CYDisplayMove(CYCursor target
) { 
  97     int offset(target
.real() - current_
.real()); 
 100         putp(tparm(parm_up_cursor
, -offset
)); 
 102         putp(tparm(parm_down_cursor
, offset
)); 
 104     putp(tparm(column_address
, target
.imag())); 
 108 void CYDisplayStart(int meta
) { 
 109     rl_prep_terminal(meta
); 
 110     current_ 
= CYCursor(); 
 113 void CYDisplayUpdate() { 
 114 #if RL_READLINE_VERSION >= 0x0600 
 115     const char *prompt(rl_display_prompt
); 
 117     const char *prompt(rl_prompt
); 
 120     std::ostringstream stream
; 
 121     CYLexerHighlight(rl_line_buffer
, rl_end
, stream
, true); 
 122     std::string 
string(stream
.str()); 
 123     const char *buffer(string
.c_str()); 
 125     int width(CYDisplayWidth()); 
 126     if (width_ 
!= width
) { 
 127         current_ 
= CYCursor(); 
 128         CYDisplayOutput(NULL
, width
, prompt
); 
 129         CYDisplayOutput(NULL
, width
, buffer
, point_
); 
 132     CYDisplayMove(CYCursor()); 
 133     CYDisplayOutput(putchar
, width
, prompt
); 
 135     CYCursor 
target(CYDisplayOutput(putchar
, width
, stream
.str().c_str(), rl_point
)); 
 136     if (target
.imag() == 0) 
 140     CYDisplayMove(target
); 
 148 void CYDisplayFinish() { 
 149     rl_deprep_terminal();