⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cursesd.cc

📁 ears-0.32, linux下有用的语音信号处理工具包
💻 CC
📖 第 1 页 / 共 3 页
字号:
          print_item (list_, items[scroll * 3],            items[scroll * 3 + 1],            status[scroll], 0, TRUE, radio_flag, menu_flag);          list_->noutrefresh ();          /* print the up/down arrows */          move (box_y, box_x + check_x + 5);          attrset (scroll ? a(uarrow_attr) : a(menubox_attr));          addch (scroll ? ACS_UARROW : ACS_HLINE);          move (box_y, box_x + check_x + 6);          addch (scroll ? '(' : ACS_HLINE);          move (box_y, box_x + check_x + 7);          addch (scroll ? '-' : ACS_HLINE);          move (box_y, box_x + check_x + 8);          addch (scroll ? ')' : ACS_HLINE);          attrset (a(darrow_attr));          move (box_y + list_height + 1, box_x + check_x + 5);          addch (ACS_DARROW);          move (box_y + list_height + 1, box_x + check_x + 6);          addch ('(');          move (box_y + list_height + 1, box_x + check_x + 7);          addch ('+');          move (box_y + list_height + 1, box_x + check_x + 8);          addch (')');          move (cur_y, cur_x);          refresh ();          continue;  /* wait for another key press */        }         else          tmp = choice - 1;      }       else if (key == KEY_DOWN || key == '+')       {        if (choice == max_choice - 1)         {          if (scroll + choice >= item_no - 1)            continue;          /* Scroll list up */          getyx (cur_y, cur_x);          if (list_height > 1)           {          /* De-highlight current last item before scrolling up */            print_item (list_, items[(scroll + max_choice - 1) * 3],              items[(scroll + max_choice - 1) * 3 + 1],              status[scroll + max_choice - 1], max_choice - 1, FALSE,               radio_flag, menu_flag);            list_->scrollok (TRUE);            list_->scroll ();            list_->scrollok (FALSE);          }          scroll++;          print_item (list_, items[(scroll + max_choice - 1) * 3],              items[(scroll + max_choice - 1) * 3 + 1],              status[scroll + max_choice - 1], max_choice - 1, TRUE,               radio_flag, menu_flag);          list_->noutrefresh ();          /* print the up/down arrows */          attrset (a(uarrow_attr));          move (box_y, box_x + check_x + 5);          addch (ACS_UARROW);          move (box_y, box_x + check_x + 6);          addstr ("(-)");          move (box_y + list_height + 1, box_x + check_x + 5);          attrset (scroll + choice < item_no - 1 ?              a(darrow_attr) : a(menubox_border_attr));          addch (scroll + choice < item_no - 1 ? ACS_DARROW : ACS_HLINE);          move (box_y + list_height + 1, box_x + check_x + 6);          addch (scroll + choice < item_no - 1 ? '(' : ACS_HLINE);          move (box_y + list_height + 1, box_x + check_x + 7);          addch (scroll + choice < item_no - 1 ? '+' : ACS_HLINE);          move (box_y + list_height + 1, box_x + check_x + 8);          addch (scroll + choice < item_no - 1 ? ')' : ACS_HLINE);          move (cur_y, cur_x);          refresh ();          continue;  /* wait for another key press */        }         else          tmp = choice + 1;      }       else if (key == ' ')       {  /* Toggle item status */        if (menu_flag) continue;        if (!radio_flag)         {          status[scroll + choice] = !status[scroll + choice];          getyx (cur_y, cur_x);          list_->move (choice, check_x);          list_->attrset (a(check_selected_attr));          list_->printw ("[%c]", status[scroll + choice] ? 'X' : ' ');        }         else         {          if (!status[scroll + choice])           {            for (int i = 0; i < item_no; i++)              status[i] = 0;            status[scroll + choice] = 1;            getyx (cur_y, cur_x);            for (int i = 0; i < max_choice; i++)              print_item (list_, items[(scroll + i) * 3],                items[(scroll + i) * 3 + 1],                status[scroll + i], i, i == choice, radio_flag, menu_flag);          }        }        list_->noutrefresh ();        move (cur_y, cur_x);        refresh ();        continue;  /* wait for another key press */      }      if (tmp != choice)       {        /* De-highlight current item */        getyx (cur_y, cur_x);        print_item (list_, items[(scroll + choice) * 3],            items[(scroll + choice) * 3 + 1],            status[scroll + choice], choice, FALSE, radio_flag, menu_flag);        /* Highlight new item */        choice = tmp;        print_item (list_, items[(scroll + choice) * 3],            items[(scroll + choice) * 3 + 1],            status[scroll + choice], choice, TRUE, radio_flag, menu_flag);        list_->noutrefresh ();        move (cur_y, cur_x);        refresh ();      }      continue;    /* wait for another key press */    }    switch (key)     {    case 'C':    case 'c':      key_=0;      return;    case 0x09:    case KEY_LEFT:    case KEY_RIGHT:      if (!button)       {        button = 1;  /* "Cancel" button selected */        print_button ("  OK  ", y, x, FALSE);        print_button ("Cancel", y, x + 14, TRUE);      }       else       {        button = 0;  /* "OK" button selected */        print_button ("Cancel", y, x + 14, FALSE);        print_button ("  OK  ", y, x, TRUE);      }      refresh ();      break;    case 'O':    case 'o':    case 0x0d:      for (int i = 0; i < item_no; i++)      {        if (status[i])           choice_=i;        choices_[i] = (status[i]!=0);      }      if (menu_flag) choice_=choice+scroll;      key_=!button;      return;    case 0x1b:      key_=-1;      return;    }  }  key_=-1;  return;      /* ESC pressed */}//-----------------------------privates------------------------------/* * Print menu item */void NCchecklist::print_item (NCursesWindow * win, const char *tag, const char *item, int status, int choice, bool selected, bool radio_flag, bool menu_flag){  win->attrset (a(menubox_attr));  win->move (choice, 0);  for (int i = 0; i <= win->maxx(); i++)    win->addch (' ');  win->move (choice, check_x);  if (!menu_flag)  {    win->attrset (selected ? a(check_selected_attr) : a(check_attr));    if (!radio_flag)      win->printw ("[%c]", status ? 'X' : ' ');    else      win->printw ("(%c)", status ? 'X' : ' ');    win->attrset (a(menubox_attr));    win->addch (' ');  }  win->attrset (selected ? a(tag_key_selected_attr) : a(tag_key_attr));  win->addch (tag[0]);  win->attrset (selected ? a(tag_selected_attr) : a(tag_attr));  win->addstr (tag + 1);  win->move (choice, item_x);  win->attrset (selected ? a(item_selected_attr) : a(item_attr));  win->addstr (item);}//============================NCradiolist================================NCradiolist::~NCradiolist() {}//============================NCmenubox==================================NCmenubox::~NCmenubox() {}//============================NCinputbox================================NCinputbox::NCinputbox (const char *title, const char *prompt, int x, int y,                         int height, int width, const char *init): NCursesDialog(x,y,height,width,title), str_max_len_(2047){  key_ = 0;  str_ = new char[str_max_len_+1];  char *instr = str_;  int button=-1, scroll=0;  keypad (TRUE);  leaveok(FALSE);  button_bar();  attrset (a(dialog_attr));  print_autowrap (prompt, width - 2, 1, 3);  /* Draw the input field box */  int box_width = width - 6;  int x,y;  getyx (y, x);  int box_y = y + 2;  int box_x = (width - box_width) / 2;  draw_box (box_x - 1, y+1, box_width + 2, 3, border_attr, dialog_attr);  x = width / 2 - 11;  y = height - 2;  print_button ("Cancel", y, x + 14, FALSE);  print_button ("  OK  ", y, x, TRUE);  /* Set up the initial value */  move (box_y, box_x);  attrset (a(inputbox_attr));  if (!init)    instr[0] = '\0';  else    strcpy (instr, init);  int input_x = strlen (instr);  if (input_x >= box_width)   {    int scroll = input_x - box_width + 1;    input_x = box_width - 1;    for (int i = 0; i < box_width - 1; i++)      addch (instr[scroll + i]);  }   else    addstr (instr);  move (box_y, box_x + input_x);  refresh ();  int key=0;  while (key != 0x1b)   {    key = getch ();    if (button == -1)     {	/* Input box selected */      switch (key)       {      case 0x09:      case KEY_UP:      case KEY_DOWN:        break;      case KEY_LEFT:      case KEY_RIGHT:        continue;      case KEY_BACKSPACE:      case 127:        if (input_x || scroll)         {          attrset (a(inputbox_attr));          if (!input_x)           {            scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1);            move (box_y, box_x);            for (int i = 0; i < box_width; i++)            addch (instr[scroll + input_x + i] ?                   instr[scroll + input_x + i] : ' ');            input_x = strlen (instr) - scroll;          }           else            input_x--;                    instr[scroll + input_x] = '\0';          move (box_y, input_x + box_x);          addch (' ');          move (box_y, input_x + box_x);          refresh ();        }        continue;      default:        if (key < 0x100 && isprint (key) && key!=0x0d)         {          if (scroll + input_x < str_max_len_)           {            attrset (a(inputbox_attr));            instr[scroll + input_x] = key;            instr[scroll + input_x + 1] = '\0';            if (input_x == box_width - 1)             {              scroll++;              move (box_y, box_x);              for (int i = 0; i < box_width - 1; i++)                addch (instr[scroll + i]);            }             else             {              move (box_y, input_x++ + box_x);              addch (key);            }            refresh ();          }           else            flash ();  /* Alarm user about overflow */          continue;        }      }    }    switch (key)     {    case 'O':    case 'o':      key_=1;      return;    case 'C':    case 'c':      key_=0;      return;    case KEY_UP:    case KEY_LEFT:      switch (button)       {      case -1:        button = 1;  /* Indicates "Cancel" button is selected */        print_button ("  OK  ", y, x, FALSE);        print_button ("Cancel", y, x + 14, TRUE);        refresh ();        break;      case 0:        button = -1;  /* Indicates input box is selected */        print_button ("Cancel", y, x + 14, FALSE);        print_button ("  OK  ", y, x, TRUE);        move (box_y, box_x + input_x);        refresh ();        break;      case 1:        button = 0;  /* Indicates "OK" button is selected */        print_button ("Cancel", y, x + 14, FALSE);        print_button ("  OK  ", y, x, TRUE);        refresh ();        break;      }      break;    case 0x09:    case KEY_DOWN:    case KEY_RIGHT:      switch (button)       {      case -1:        button = 0;  /* Indicates "OK" button is selected */        print_button ("Cancel", y, x + 14, FALSE);        print_button ("  OK  ", y, x, TRUE);        refresh ();        break;      case 0:        button = 1;  /* Indicates "Cancel" button is selected */        print_button ("  OK  ", y, x, FALSE);        print_button ("Cancel", y, x + 14, TRUE);        refresh ();        break;      case 1:        button = -1;  /* Indicates input box is selected */        print_button ("Cancel", y, x + 14, FALSE);        print_button ("  OK  ", y, x, TRUE);        move (box_y, box_x + input_x);        refresh ();        break;      }      break;    case ' ':    case 0x0d:      key_= (button == -1 ? 1 : button);      return;    case 0x1b:      break;    }  }  key_=-1;  return;      /* ESC pressed */}//============================NCtextbox==================================NCtextbox::NCtextbox (const char* title, const char* file, int x, int y,                       int height, int width): NCursesDialog (x,y,height,width,title), text_(0), str_max_len_(2047),  buf_size_(10*1024), hscroll_(0),   page_(0), buf_(0), line_(0), begin_reached_(true), end_reached_(false){  /* Open input file for reading */  if ((fd_ = open (file, O_RDONLY)) == -1)   {    endwin ();    fprintf (stderr,     "\nCan't open input file %s in dialog_textbox().\n",file);    exit (-1);  }  /* Get file size. Actually, 'file_size' is the real file size - 1,     since it's only the last byte offset from the beginning */  if ((file_size_ = lseek (fd_, 0, SEEK_END)) == -1)   {    endwin ();    fprintf (stderr, "\nError getting file size in dialog_textbox().\n");    exit (-1);  }  /* Restore file pointer to beginning of file after getting file size */  if (lseek (fd_, 0, SEEK_SET) == -1)   {    endwin ();    fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n");    exit (-1);  }  /* Allocate space for read buffer */  buf_ = new char[buf_size_];  line_ = new char[str_max_len_+1];  if ((bytes_read_ = read (fd_, buf_, buf_size_)) == -1)   {    endwin ();    fprintf (stderr, "\nError reading file in dialog_textbox().\n");    exit (-1);  }  buf_[bytes_read_] = '\0';  /* mark end of valid data */  page_ = buf_;    /* page is pointer to start of page to be displayed */  char search_term[str_max_len_ + 1];  search_term[0] = '\0';  /* no search term entered yet */  keypad (TRUE);  /* Create window for text region, used for scrolling text */  text_ = new NCursesWindow (*this, height - 4, width - 2, y + 1, x + 1);  text_->keypad (TRUE);  button_bar();  print_button (" EXIT ", height - 2, width / 2 - 4, TRUE);  noutrefresh ();  int cur_x, cur_y;  getyx (cur_y, cur_x);  /* Save cursor position */  /* Print first page of text *///  text_->attr_clear (height - 4, width - 2, a(dialog_attr));  text_->attrset (a(dialog_attr));  print_page (height - 4, width - 2);  print_position (height, width);  move (cur_y, cur_x);  /* Restore cursor position */  refresh ();  int key=0, fpos;  while ((key != 0x1b) && (key != 0x0d))   {    key = getch ();    switch (key)     {      case 'E':  /* Exit */      case 'e':      case 0x0d:        close (fd_);        key_=0;        return;      case 'g':  /* First page */      case KEY_HOME:        if (!begin_reached_)         {          begin_reached_ = true;          /* First page not in buffer? */          if ((fpos = lseek (fd_, 0, SEEK_CUR)) == -1)           {            endwin ();            fprintf (stderr,              "\nError moving file pointer in dialog_textbox().\n");            exit (-1);          }          if (fpos > bytes_read_)          {            if (lseek (fd_, 0, SEEK_SET) == -1)             {               endwin ();              fprintf (stderr, "\nError moving file pointer in "               "dialog_textbox().\n");              exit (-1);            }            if ((bytes_read_ = read (fd_, buf_, buf_size_)) == -1)             {              endwin ();              fprintf (stderr,                 "\nError reading file in dialog_textbox().\n");              exit (-1);            }            buf_[bytes_read_] = '\0';          }          page_ = buf_;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -