Changeset 38cc669


Ignore:
Timestamp:
Mar 23, 2010, 5:23:43 PM (10 years ago)
Author:
Nelson Elhage <nelhage@ksplice.com>
Branches:
master, release-1.6, release-1.7, release-1.8, release-1.9
Children:
0d17295
Parents:
8dfb59c
git-author:
Nelson Elhage <nelhage@mit.edu> (03/13/10 23:54:51)
git-committer:
Nelson Elhage <nelhage@ksplice.com> (03/23/10 17:23:43)
Message:
Create/destroy editwins rather than reusing a single one.
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    r8dfb59c r38cc669  
    25662566  /* if we get two arguments, ask for the password */
    25672567  if (argc==2) {
     2568    owl_function_start_password("AIM Password: ");
    25682569    owl_editwin_set_cbdata(owl_global_get_typwin(&g),
    25692570                           owl_strdup(argv[1]), owl_free);
    25702571    owl_editwin_set_callback(owl_global_get_typwin(&g),
    25712572                             owl_callback_aimlogin);
    2572     owl_function_start_password("AIM Password: ");
    25732573    return(NULL);
    25742574  } else {
     
    26992699  }
    27002700
    2701   owl_editwin_fullclear(e);
    27022701  owl_global_set_needrefresh(&g);
     2702  owl_global_pop_context(&g);
     2703
    27032704  owl_global_set_typwin_inactive(&g);
    2704   owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
    2705 
    2706   owl_global_pop_context(&g);
    27072705}
    27082706
     
    27612759  owl_history_store(hist, owl_editwin_get_text(e));
    27622760  owl_history_reset(hist);
     2761  cmd = owl_strdup(owl_editwin_get_text(e));
     2762
    27632763  owl_global_set_typwin_inactive(&g);
    27642764  owl_global_pop_context(&g);
    2765   cmd = owl_strdup(owl_editwin_get_text(e));
    2766   owl_editwin_fullclear(e);
     2765
    27672766  rv = owl_function_command(cmd);
    27682767  owl_free(cmd);
     
    27832782  owl_global_set_typwin_inactive(&g);
    27842783  owl_global_pop_context(&g);
    2785   owl_editwin_fullclear(e);
     2784
    27862785  owl_global_set_needrefresh(&g);
    27872786}
     
    27962795
    27972796  owl_function_run_buffercommand();
    2798   owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
    2799   owl_editwin_fullclear(e);
     2797
    28002798  owl_global_set_typwin_inactive(&g);
    28012799  owl_global_pop_context(&g);
  • editwin.c

    r8dfb59c r38cc669  
    6464#define WHITESPACE " \n\t"
    6565
    66 owl_editwin *owl_editwin_allocate(void)
     66static owl_editwin *owl_editwin_allocate(void)
    6767{
    6868  owl_editwin *e;
     
    8080    oe_release_excursion(e, e->excursions);
    8181  }
     82  oe_destroy_cbdata(e);
    8283
    8384  owl_free(e);
     
    116117}
    117118
    118 /* initialize the editwin e.
    119  * 'win' is an already initialzed curses window that will be used by editwin
    120  */
    121 void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
     119static void _owl_editwin_init(owl_editwin *e,
     120                              WINDOW *win,
     121                              int winlines,
     122                              int wincols,
     123                              int style,
     124                              owl_history *hist)
    122125{
    123126  e->buff=owl_malloc(INCR);
     
    148151}
    149152
     153owl_editwin *owl_editwin_new(WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
     154{
     155  owl_editwin *e = owl_editwin_allocate();
     156
     157  _owl_editwin_init(e, win, winlines, wincols, style, hist);
     158  return e;
     159}
     160
    150161void owl_editwin_set_curswin(owl_editwin *e, WINDOW *w, int winlines, int wincols)
    151162{
     
    249260}
    250261
    251 void owl_editwin_new_style(owl_editwin *e, int newstyle, owl_history *h)
    252 {
    253   e->hist = h;
    254 
    255   if (e->style==newstyle) return;
    256 
    257   if (newstyle==OWL_EDITWIN_STYLE_MULTILINE) {
    258     e->style=newstyle;
    259   } else if (newstyle==OWL_EDITWIN_STYLE_ONELINE) {
    260     e->style=newstyle;
    261 
    262     /* nuke everything after the first line */
    263     owl_editwin_move_to_top(e);
    264     owl_editwin_move_to_end_of_line(e);
    265     owl_editwin_replace(e, oe_count_glyphs(e->buff + e->index),  "");
    266   }
    267 }
    268 
    269 /* completly reinitialize the buffer */
    270 void owl_editwin_fullclear(owl_editwin *e)
    271 {
    272   owl_free(e->buff);
    273   owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
    274   e->callback = NULL;
    275   oe_destroy_cbdata(e);
    276 }
    277 
    278262/* clear all text except for locktext and put the cursor at the
    279263 * beginning
     
    294278
    295279  owl_free(e->buff);
    296   owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
     280  _owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
    297281
    298282  if (lock > 0) {
  • functions.c

    r8dfb59c r38cc669  
    283283
    284284  /* create and setup the editwin */
     285  owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_MULTILINE,
     286                               owl_global_get_msg_history(&g));
    285287  e = owl_global_get_typwin(&g);
    286   owl_editwin_new_style(e, OWL_EDITWIN_STYLE_MULTILINE,
    287                         owl_global_get_msg_history(&g));
    288   owl_editwin_clear(e);
    289288  owl_editwin_set_dotsend(e);
    290289  s = owl_sprintf("----> %s\n", line);
     
    292291  owl_free(s);
    293292
    294   /* make it active */
    295   owl_global_set_typwin_active(&g);
    296 
    297   owl_editwin_set_cbdata(owl_global_get_typwin(&g), data, cleanup);
    298   owl_editwin_set_callback(owl_global_get_typwin(&g), callback);
     293  owl_editwin_set_cbdata(e, data, cleanup);
     294  owl_editwin_set_callback(e, callback);
    299295  owl_global_push_context(&g, OWL_CTX_EDITMULTI, e, "editmulti");
    300296}
     
    19131909  owl_editwin *tw;
    19141910
     1911  owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
    19151912  tw=owl_global_get_typwin(&g);
    1916   owl_global_set_typwin_active(&g);
    1917   owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE,
    1918                         owl_global_get_cmd_history(&g));
    19191913
    19201914  owl_editwin_set_locktext(tw, "command: ");
     
    19311925  owl_editwin *tw;
    19321926
     1927  owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
    19331928  tw=owl_global_get_typwin(&g);
    1934   owl_global_set_typwin_active(&g);
    1935   owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
    19361929
    19371930  owl_editwin_set_locktext(tw, line);
     
    19471940  owl_editwin *tw;
    19481941
    1949   tw=owl_global_get_typwin(&g);
    1950   owl_global_set_typwin_active(&g);
    1951   owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
     1942  owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g));
     1943  tw = owl_global_get_typwin(&g);
    19521944  owl_editwin_set_echochar(tw, '*');
    19531945
  • global.c

    r8dfb59c r38cc669  
    4545  g->rightshift=0;
    4646
    47   g->tw = owl_editwin_allocate();
    48   owl_editwin_init(g->tw, NULL, owl_global_get_typwin_lines(g), g->cols, OWL_EDITWIN_STYLE_ONELINE, NULL);
     47  g->tw = NULL;
    4948
    5049  owl_keyhandler_init(&g->kh);
     
    171170  _owl_panel_set_window(&g->typpan, newwin(typwin_lines, cols, g->recwinlines+2, 0));
    172171
    173   owl_editwin_set_curswin(g->tw, owl_global_get_curs_typwin(g), typwin_lines, g->cols);
     172  if (g->tw)
     173      owl_editwin_set_curswin(g->tw, owl_global_get_curs_typwin(g), typwin_lines, g->cols);
    174174
    175175  idlok(owl_global_get_curs_typwin(g), FALSE);
     
    368368}
    369369
    370 void owl_global_set_typwin_active(owl_global *g) {
    371   int d = owl_global_get_typewindelta(g);
     370void owl_global_set_typwin_active(owl_global *g, int style, owl_history *hist) {
     371  int d;
     372  d = owl_global_get_typewindelta(g);
    372373  if (d > 0)
    373374      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
    374375
     376  g->tw = owl_editwin_new(owl_global_get_curs_typwin(g),
     377                          owl_global_get_typwin_lines(g),
     378                          g->cols,
     379                          style,
     380                          hist);
    375381  g->typwinactive=1;
    376382}
     
    382388
    383389  g->typwinactive=0;
     390
     391  owl_editwin_delete(g->tw);
     392  werase(owl_global_get_curs_typwin(g));
     393  g->tw = NULL;
    384394}
    385395
     
    513523  owl_mainwin_redisplay(&(g->mw));
    514524  sepbar(NULL);
    515   owl_editwin_redisplay(g->tw);
     525  if (g->tw)
     526      owl_editwin_redisplay(g->tw);
    516527  owl_function_full_redisplay();
    517528
  • perlglue.xs

    r1b1cd2c r38cc669  
    549549        int count;
    550550        const char *string;
    551         CODE:
    552                 RETVAL = owl_editwin_replace(owl_global_get_typwin(&g), count, string);
     551        PREINIT:
     552                owl_editwin *e;
     553        CODE:
     554                e = owl_global_get_typwin(&g);
     555                if (e) {
     556                        RETVAL = owl_editwin_replace(e, count, string);
     557                } else {
     558                        RETVAL = 0;
     559                }
    553560        OUTPUT:
    554561                RETVAL
     
    557564point_move(delta)
    558565        int delta;
    559         CODE:
    560                 RETVAL = owl_editwin_point_move(owl_global_get_typwin(&g), delta);
     566        PREINIT:
     567                owl_editwin *e;
     568        CODE:
     569                e = owl_global_get_typwin(&g);
     570                if (e) {
     571                        RETVAL = owl_editwin_point_move(e, delta);
     572                } else {
     573                        RETVAL = 0;
     574                }
    561575        OUTPUT:
    562576                RETVAL
     
    565579replace_region(string)
    566580        const char *string;
    567         CODE:
    568                 RETVAL = owl_editwin_replace_region(owl_global_get_typwin(&g), string);
     581        PREINIT:
     582                owl_editwin *e;
     583        CODE:
     584                e = owl_global_get_typwin(&g);
     585                if (e) {
     586                        RETVAL = owl_editwin_replace_region(e, string);
     587                } else {
     588                        RETVAL = 0;
     589                }
    569590        OUTPUT:
    570591                RETVAL
     
    574595        PREINIT:
    575596                char *region;
    576         CODE:
    577                 region = owl_editwin_get_region(owl_global_get_typwin(&g));
     597                owl_editwin *e;
     598        CODE:
     599                e = owl_global_get_typwin(&g);
     600                if (e) {
     601                        region = owl_editwin_get_region(owl_global_get_typwin(&g));
     602                } else {
     603                        region = NULL;
     604                }
    578605                RETVAL = region;
    579606        OUTPUT:
     
    588615        PREINIT:
    589616                int count;
     617                owl_editwin *e;
    590618                owl_editwin_excursion *x;
    591619        CODE:
    592620        {
     621                e = owl_global_get_typwin(&g);
     622                if(!e)
     623                        croak("The edit window is not currently active!");
     624
    593625                x = owl_editwin_begin_excursion(owl_global_get_typwin(&g));
    594626                PUSHMARK(SP);
     
    612644int
    613645current_column()
    614         CODE:
    615                 RETVAL = owl_editwin_current_column(owl_global_get_typwin(&g));
     646        PREINIT:
     647                owl_editwin *e;
     648        CODE:
     649                e = owl_global_get_typwin(&g);
     650                if (e) {
     651                        RETVAL = owl_editwin_current_column(e);
     652                } else {
     653                        RETVAL = 0;
     654                }
    616655        OUTPUT:
    617656                RETVAL
     
    619658int
    620659point()
    621         CODE:
    622                 RETVAL = owl_editwin_get_point(owl_global_get_typwin(&g));
     660        PREINIT:
     661                owl_editwin *e;
     662        CODE:
     663                e = owl_global_get_typwin(&g);
     664                if (e) {
     665                        RETVAL = owl_editwin_get_point(e);
     666                } else {
     667                        RETVAL = 0;
     668                }
    623669        OUTPUT:
    624670                RETVAL
     
    626672int
    627673mark()
    628         CODE:
    629                 RETVAL = owl_editwin_get_mark(owl_global_get_typwin(&g));
    630         OUTPUT:
    631                 RETVAL
     674        PREINIT:
     675                owl_editwin *e;
     676        CODE:
     677                e = owl_global_get_typwin(&g);
     678                if (e) {
     679                        RETVAL = owl_editwin_get_mark(e);
     680                } else {
     681                        RETVAL = 0;
     682                }
     683        OUTPUT:
     684                RETVAL
Note: See TracChangeset for help on using the changeset viewer.