Scrollback - Galvin

From Gwen Morse's Wiki
Jump to: navigation, search
;Scroll back history tool
;Version 2.10 Galvin
;
;PgUp brings you into the scroll back; places the world in the background;
;     also it pages up thru the scroll back one page at a time.
;PgDn Does the same as above except it doesn't activate scroll back.
;control - T to jump to the top
;control - B to jump to the bottom
;control - Q to exit the scroll back
;
;NOTES:
;Make sure scroll_history_size is set to the what ever /histsize is set
;to, if not the scroll_back will be flakey :)
;the /FG and /BG may cause problems for people using mulitple worlds.
;till I find a way to supress output but have it buffered this is the
;only way I know how.
;If anyone knows of a better way to turn off activity messages or trigger
;messages from other worlds let me know.
;thanks.  The code may be a little buggy but am using it regulary now.

;==============================================================================
;This function is to be used if you want to write stuff directly into the input
;buffer.  This will automatically break long lines up into multiple lines so they
;show up in the scroll back correctly.
;USAGE:
;InputHist_MultiLine("this is a string of text", ScreenWidth)
;The string will be broken into even segments of screenwidth
;NOTE: You need to write stuff you type into the keyboard into the history buffer
;      if you want to see it in the scrollback.
;to make such a macro that can catch every you type this is how:
;/def -ag -mregexp -F -h'SEND ^.*$' chat_send = \
;  /test InputHist_MultiLine(strcat("> ",{P0}), 80)%;\
;  /test send({P0})
;======================================================================

/def InputHist_MultiLine = \
 /test IHML_St := {1}%;\
 /test IHML_ScreenWidth := %2%;\
 /test IHML_Pos := 0%;\
 /while (IHML_Pos < strlen(IHML_St)) \
   /test RECORDLINE(substr(IHML_St, IHML_Pos, IHML_ScreenWidth))%;\
   /test IHML_Pos := IHML_Pos + IHML_ScreenWidth%;\
 /DONE

;----------------------------------------------------------------------
;the size of your scroll back buffer
/set scroll_history_size 10000

;scroll back is on or off flag
/set scroll_back_on 0

;hit top of scroll back buffer flag
/set scroll_back_stop 0

;the current size of the scroll back buffer when in scroll back mode
/set scroll_total_lines 0

;the current position in the scroll back buffer when in scroll back mode
/set scroll_back_p 0
/set scroll_back_p1 0

;get the current size of the history buffer
/def total_lines = \
 /test total_lines_st := $$(/recall -agG -g #1)%;\
 /test total_lines_p := strstr(total_lines_st, ":")%;\
 /test total_lines_v := substr(total_lines_st, 0, total_lines_p)%;\
 /return substr(total_lines_st, 0, total_lines_p)

;find top of scroll buffer, value passed must begin before top
;value returned will equal the line number at the start of the top

;define scrollback keybindings
/def def_scroll_back = \
 /test scroll_back_on := 1%;\
 /screenout_off%;\
 /test scroll_back_stop := 0%;\
 /test scroll_back_screen := (lines() - (visual ? isize+1 : 0)) - 5%;\
 /test scroll_total_lines := total_lines()%;\
 /test scroll_back_p := scroll_total_lines%;\
 /unbind ^[[A%;\
 /unbind ^[[B%;\
 /def -iB'up'   hist_back_line_d = /hist_back_line%;\
 /def -iB'down' hist_down_line_d = /hist_down_line%;\
 /def -ib'^t'   hist_home_line_d = /hist_home_line%;\
 /def -ib'^b'   hist_end_line_d  = /hist_end_line%;\
 /def -ib'^q'   hist_quit_line_d = /undef_scroll_back

;reset keybindings
/def undef_scroll_back = \
 /cursor_upperleft%;\
 /screenout_on%;\
 /set scroll_back_p 0%;\
 /set scroll_back_p1 0%;\
 /set scroll_back_on 0%;\
 /undef hist_back_line_d%;\
 /undef hist_down_line_d%;\
 /undef hist_home_line_d%;\
 /undef hist_end_line_d%;\
 /undef hist_quit_line_d%;\
 /def -iB'up' = /dokey recallb%;\
 /def -iB'down' = /dokey recallf%;\

;Set cursor position to upper left hand of screen
;NOTE: this may not work on all terminals
;the escape sequence is to erase the screen and place the
;cursor at the upper left.
/def cursor_upperleft = \
 /test cursor_oldemulation := emulation%;\
 /set emulation=raw%;\
 /EVAL /echo -aG $[strcat(char(27),"[2J")]%;\
 /set emulation=%{cursor_oldemulation}

;Draw the scroll back
/def draw_scrollback = \
 /cursor_upperleft%;\
 /recall -agG -g %{1}-%{2}

;/test tfwrite("o", strcat({1},":",{2}))

;Turn off all screen output.
/def screenout_off = \
 /hook OFF%;\
 /def -ag -q -hBACKGROUND _nobackground_%;\
 /def -ag -q -hACTIVITY   _noactivity_%;\
 /BG

;Turn on all screen output.
/def screenout_on = \
 /hook ON%;\
 /undef _nobackground_%;\
 /undef _noactivity_%;\
 /FG

/def -b'^[[5~' scroll_back =\
 /IF (!scroll_back_on) \
   /def_scroll_back%;\
 /ENDIF%;\
 /IF (scroll_back_stop) \
  /beep 1%;\
  /ELSE \
    /test scroll_back_p := scroll_back_p - scroll_back_screen - 1%;\
    /IF (scroll_back_p <= 1) \
      /test scroll_back_p := 1%;\
      /test scroll_back_stop := 1%;\
    /ENDIF%;\
    /IF (scroll_back_p < (scroll_total_lines - scroll_history_size) ) \
      /test scroll_back_stop := 1%;\
      /test scroll_back_p := scroll_total_lines - scroll_history_size%;\
    /ENDIF%;\
    /test scroll_back_p1 := scroll_back_p + scroll_back_screen%;\
    /test draw_scrollback(scroll_back_p,scroll_back_p1)%;\
 /ENDIF

/def -b'^[[6~' scroll_down =\
 /IF (scroll_back_on) \
   /IF (scroll_back_p + scroll_back_screen = scroll_total_lines) \
     /beep 1%;\
   /ELSE \
     /test scroll_back_stop := 0%;\
     /test scroll_back_p := scroll_back_p + scroll_back_screen + 1%;\
     /IF (scroll_back_p > scroll_total_lines) \
       /test scroll_back_p := scroll_total_lines - scroll_back_screen%;\
     /ENDIF%;\
     /test scroll_back_p1 := scroll_back_p + scroll_back_screen%;\
     /test draw_scrollback(scroll_back_p,scroll_back_p1)%;\
   /ENDIF%;\
 /ENDIF

/def hist_down_line = \
  /IF (scroll_back_p + scroll_back_screen = scroll_total_lines) \
    /beep 1%;\
  /ELSE \
    /test scroll_back_stop := 0%;\
    /test scroll_back_p := scroll_back_p + 1%;\
    /IF ( (scroll_back_p + scroll_back_screen) > scroll_total_lines) \
      /test scroll_back_p := scroll_total_lines - 1%;\
    /ENDIF%;\
    /test scroll_back_p1 := scroll_back_p + scroll_back_screen%;\
    /test draw_scrollback(scroll_back_p,scroll_back_p1)%;\
  /ENDIF%;\

/def hist_back_line = \
 /IF (scroll_back_p = (scroll_total_lines - scroll_history_size)) \
   /beep 1%;\
 /ELSE \
   /IF (scroll_back_stop) \
    /beep 1%;\
    /ELSE \
     /test scroll_back_p := scroll_back_p - 1%;\
     /IF (scroll_back_p <= 1) \
       /test scroll_back_p := 1%;\
       /test scroll_back_stop := 1%;\
     /ENDIF%;\
     /IF (scroll_back_p < (scroll_total_lines - scroll_history_size)) \
       /test scroll_back_stop := 1%;\
       /test scroll_back_p := scroll_total_lines - scroll_history_size%;\
     /ENDIF%;\
     /test scroll_back_p1 := scroll_back_p + scroll_back_screen%;\
     /test draw_scrollback(scroll_back_p,scroll_back_p1)%;\
     /ENDIF%;\
 /ENDIF

/def hist_home_line = \
 /beep on%;\
 /test scroll_back_p := scroll_total_lines - scroll_history_size%;\
 /IF (scroll_back_p < 1) \
   /test scroll_back_p := 1%;\
 /ENDIF%;\
 /test scroll_back_p1 := scroll_back_p + scroll_back_screen%;\
 /test draw_scrollback(scroll_back_p,scroll_back_p1)%;\
 /test scroll_back_stop := 1

/def hist_end_line = \
 /test scroll_back_p := scroll_total_lines - scroll_back_screen%;\
 /IF (scroll_back_p < 1) \
   /test scroll_back_p := 1%;\
 /ENDIF%;\
 /test scroll_back_p1 := scroll_back_p + scroll_back_screen%;\
 /test draw_scrollback(scroll_back_p,scroll_back_p1)%;\
 /test scroll_back_stop := 0