MCPcopy Create free account
hub / github.com/DFHack/dfhack / prompt_loop

Method prompt_loop

library/Console-posix.cpp:518–813  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

516 }
517
518 int prompt_loop(std::recursive_mutex * lock, CommandHistory & history)
519 {
520 int fd = STDIN_FILENO;
521 size_t plen = prompt.size();
522 int history_index = 0;
523 raw_buffer.clear();
524 raw_cursor = 0;
525 /* The latest history entry is always our current buffer, that
526 * initially is just an empty string. */
527 const std::string empty;
528 history.add(empty);
529 if (::write(fd,prompt.c_str(),prompt.size()) == -1)
530 return Console::FAILURE;
531 while(1)
532 {
533 unsigned char c;
534 unsigned char seq[2], seq2;
535 lock->unlock();
536 if(!read_char(c))
537 {
538 lock->lock();
539 return Console::SHUTDOWN;
540 }
541 lock->lock();
542 const int old_cursor = raw_cursor;
543 /* Only autocomplete when the callback is set. It returns < 0 when
544 * there was an error reading from fd. Otherwise it will return the
545 * character that should be handled next. */
546 if (c == 9)
547 {
548 /*
549 if( completionCallback != NULL) {
550 c = completeLine(fd,prompt,buf,buflen,&len,&pos,cols);
551 // Return on errors
552 if (c < 0) return len;
553 // Read next character when 0
554 if (c == 0) continue;
555 }
556 else
557 {
558 // ignore tab
559 continue;
560 }
561 */
562 // just ignore tabs
563 continue;
564 }
565
566 switch(c)
567 {
568 case 13: // enter
569 case 10:
570 history.remove();
571 return raw_buffer.size();
572 case 3: // ctrl-c
573 return Console::RETRY;
574 case 127: // backspace
575 case 8: // ctrl-h

Callers

nothing calls this directly

Calls 14

toLocaleMBFunction · 0.85
fromLocaleMBFunction · 0.85
mbrtoc32Function · 0.85
c_strMethod · 0.80
clearFunction · 0.70
writeFunction · 0.50
sizeMethod · 0.45
clearMethod · 0.45
addMethod · 0.45
unlockMethod · 0.45
lockMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected