Skip to content

Prompt-multiline jumps to the bottom of the screen on first character insertion #404

@jmcken8

Description

@jmcken8

Minimal repro case (mac OSX):

#include "cpp-terminal/exception.hpp"
#include "cpp-terminal/key.hpp"
#include "cpp-terminal/prompt.hpp"
#include "cpp-terminal/terminal.hpp"
#include "cpp-terminal/tty.hpp"
#include <cpp-terminal/terminal_initializer.hpp>
#include <iostream>

bool determine_completeness(const std::string& command)
{
  // Determine if the statement is complete
  if (command.size() > 1 && command.substr(command.size() - 2, 1) == "\\")
    return false;
  return true;
}
int main()
{
  try
  {
    Term::terminal.setOptions(Term::Option::NoClearScreen,
                              Term::Option::SignalKeys,
                              Term::Option::NoCursor,
                              Term::Option::Raw);
    if (!Term::is_stdin_a_tty())
    {
      throw Term::Exception("The terminal is not attached to a TTY and therefore can't "
                            "catch user input. Exiting...");
    }
    Term::cout << "Interactive prompt.\n"
               << "  * Use Ctrl-D to exit.\n"
               << "  * Use Enter to submit.\n"
               << "  * Features:\n"
               << "    - Editing (Keys: Left, Right, Home, End, Backspace)\n"
               << "    - History (Keys: Up, Down)" << std::endl;
               std::vector<std::string> history;
               std::function<bool(std::string)> iscomplete = determine_completeness;
    std::string input = Term::prompt_multiline("Query> ", history, iscomplete);
    return 0;
  }
  catch (const Term::Exception& re)
  {
    std::cerr << "cpp-terminal error: " << re.what() << std::endl;
    return 2;
  }
  return 0;
}

Then clear the terminal and run.

I think I see what the issue is, I'll post a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions