From 4cf547bf9f9b5291cb3d57ce5235a38bf49c9112 Mon Sep 17 00:00:00 2001 From: Adler Perotte Date: Sun, 5 Feb 2017 13:12:58 -0500 Subject: [PATCH 1/2] added a command line flag and associated code to support using a dumb terminal --- include/cling/Interpreter/ClingOptions.inc | 2 ++ include/cling/Interpreter/InvocationOptions.h | 1 + lib/Interpreter/InvocationOptions.cpp | 3 ++- lib/UserInterface/UserInterface.cpp | 3 +++ lib/UserInterface/textinput/TextInput.cpp | 13 +++++++++---- lib/UserInterface/textinput/TextInput.h | 7 +++++++ 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/cling/Interpreter/ClingOptions.inc b/include/cling/Interpreter/ClingOptions.inc index 2bb6f327f7..b4f9505500 100644 --- a/include/cling/Interpreter/ClingOptions.inc +++ b/include/cling/Interpreter/ClingOptions.inc @@ -18,6 +18,8 @@ PREFIX(prefix_2, {"--" COMMA 0}) OPTION(prefix_0, "", INPUT, Input, INVALID, INVALID, 0, 0, 0, 0, 0) OPTION(prefix_0, "", UNKNOWN, Unknown, INVALID, INVALID, 0, 0, 0, 0, 0) +OPTION(prefix_2, "dumbterm", _dumbterm, Flag, INVALID, INVALID, 0, 0, 0, + "Using a dumb terminal", 0) OPTION(prefix_2, "errorout", _errorout, Flag, INVALID, INVALID, 0, 0, 0, "Do not recover from input errors", 0) OPTION(prefix_3, "help", help, Flag, INVALID, INVALID, 0, 0, 0, diff --git a/include/cling/Interpreter/InvocationOptions.h b/include/cling/Interpreter/InvocationOptions.h index 668e3e1210..c23c5968a7 100644 --- a/include/cling/Interpreter/InvocationOptions.h +++ b/include/cling/Interpreter/InvocationOptions.h @@ -66,6 +66,7 @@ namespace cling { bool ErrorOut; bool NoLogo; + bool DumbTerm; bool ShowVersion; bool Help; bool Verbose() const { return CompilerOpts.Verbose; } diff --git a/lib/Interpreter/InvocationOptions.cpp b/lib/Interpreter/InvocationOptions.cpp index 2b2c87384d..c9192d4321 100644 --- a/lib/Interpreter/InvocationOptions.cpp +++ b/lib/Interpreter/InvocationOptions.cpp @@ -63,6 +63,7 @@ namespace { InputArgList& Args) { Opts.ErrorOut = Args.hasArg(OPT__errorout); Opts.NoLogo = Args.hasArg(OPT__nologo); + Opts.DumbTerm = Args.hasArg(OPT__dumbterm); Opts.ShowVersion = Args.hasArg(OPT_version); Opts.Help = Args.hasArg(OPT_help); if (Arg* MetaStringArg = Args.getLastArg(OPT__metastr, OPT__metastr_EQ)) { @@ -136,7 +137,7 @@ void CompilerOptions::Parse(int argc, const char* const argv[], } InvocationOptions::InvocationOptions(int argc, const char* const* argv) : - MetaString("."), ErrorOut(false), NoLogo(false), ShowVersion(false), + MetaString("."), ErrorOut(false), NoLogo(false), DumbTerm(false), ShowVersion(false), Help(false) { ArrayRef ArgStrings(argv, argv + argc); diff --git a/lib/UserInterface/UserInterface.cpp b/lib/UserInterface/UserInterface.cpp index 1549306cba..455cb6e43f 100644 --- a/lib/UserInterface/UserInterface.cpp +++ b/lib/UserInterface/UserInterface.cpp @@ -98,6 +98,9 @@ namespace cling { UITabCompletion* Completion = new UITabCompletion(m_MetaProcessor->getInterpreter()); TI.SetCompletion(Completion); + if (m_MetaProcessor->getInterpreter().getOptions().DumbTerm) { + TI.SetIsDumbTerm(true); + } std::string Line; std::string Prompt("[cling]$ "); diff --git a/lib/UserInterface/textinput/TextInput.cpp b/lib/UserInterface/textinput/TextInput.cpp index c724e61f17..3d3b197ddf 100644 --- a/lib/UserInterface/textinput/TextInput.cpp +++ b/lib/UserInterface/textinput/TextInput.cpp @@ -31,6 +31,7 @@ namespace textinput { TextInput::TextInput(Reader& reader, Display& display, const char* HistFile /* = 0 */): + fIsDumbTerm(false), fMasked(false), fAutoHistAdd(true), fLastKey(0), @@ -61,9 +62,11 @@ namespace textinput { } fContext->GetEditor()->ResetText(); - // Signal displays that the input got taken. - std::for_each(fContext->GetDisplays().begin(), fContext->GetDisplays().end(), - std::mem_fun(&Display::NotifyResetInput)); + if (!fIsDumbTerm) { + // Signal displays that the input got taken. + std::for_each(fContext->GetDisplays().begin(), fContext->GetDisplays().end(), + std::mem_fun(&Display::NotifyResetInput)); + } ReleaseInputOutput(); @@ -124,7 +127,9 @@ namespace textinput { || (*iR)->HaveBufferedInput()) { if ((*iR)->ReadInput(nRead, in)) { ProcessNewInput(in, R); - DisplayNewInput(R, OldCursorPos); + if (!IsDumbTerm()) { + DisplayNewInput(R, OldCursorPos); + } if (fLastReadResult == kRREOF || fLastReadResult == kRRReadEOLDelimiter) break; diff --git a/lib/UserInterface/textinput/TextInput.h b/lib/UserInterface/textinput/TextInput.h index abe6a16938..2ffacf298f 100644 --- a/lib/UserInterface/textinput/TextInput.h +++ b/lib/UserInterface/textinput/TextInput.h @@ -88,6 +88,13 @@ namespace textinput { void EnableAutoHistAdd(bool enable = true) { fAutoHistAdd = enable; } void AddHistoryLine(const char* line); + // Dumb terminal getter and setter + bool IsDumbTerm() const {return fIsDumbTerm;} + void SetIsDumbTerm(bool isDumbTerm) { fIsDumbTerm = isDumbTerm; } + + protected: + bool fIsDumbTerm; // whether this is a dumb terminal or not + private: void EmitSignal(char c, EditorRange& r); void ProcessNewInput(const InputData& in, EditorRange& r); From a33965a78b281a7f686a428b7c8c368b6a4f4d23 Mon Sep 17 00:00:00 2001 From: Adler Perotte Date: Sun, 5 Mar 2017 11:27:20 -0500 Subject: [PATCH 2/2] removed the flag and modified TerminalDisplay class to detect terminal type and respond appropriately when type is dumb --- include/cling/Interpreter/ClingOptions.inc | 2 -- include/cling/Interpreter/InvocationOptions.h | 1 - lib/Interpreter/InvocationOptions.cpp | 3 +-- lib/UserInterface/UserInterface.cpp | 2 +- lib/UserInterface/textinput/TerminalDisplay.h | 3 +++ lib/UserInterface/textinput/TerminalDisplayUnix.cpp | 1 + lib/UserInterface/textinput/TerminalDisplayWin.cpp | 1 + 7 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/cling/Interpreter/ClingOptions.inc b/include/cling/Interpreter/ClingOptions.inc index cf16366394..c3d1a9ab5e 100644 --- a/include/cling/Interpreter/ClingOptions.inc +++ b/include/cling/Interpreter/ClingOptions.inc @@ -18,8 +18,6 @@ PREFIX(prefix_2, {"--" COMMA 0}) OPTION(prefix_0, "", INPUT, Input, INVALID, INVALID, 0, 0, 0, 0, 0) OPTION(prefix_0, "", UNKNOWN, Unknown, INVALID, INVALID, 0, 0, 0, 0, 0) -OPTION(prefix_2, "dumbterm", _dumbterm, Flag, INVALID, INVALID, 0, 0, 0, - "Using a dumb terminal", 0) OPTION(prefix_2, "errorout", _errorout, Flag, INVALID, INVALID, 0, 0, 0, "Do not recover from input errors", 0) OPTION(prefix_3, "help", help, Flag, INVALID, INVALID, 0, 0, 0, diff --git a/include/cling/Interpreter/InvocationOptions.h b/include/cling/Interpreter/InvocationOptions.h index a3a87f7796..c01f8f4642 100644 --- a/include/cling/Interpreter/InvocationOptions.h +++ b/include/cling/Interpreter/InvocationOptions.h @@ -66,7 +66,6 @@ namespace cling { bool ErrorOut; bool NoLogo; - bool DumbTerm; bool ShowVersion; bool Help; bool NoRuntime; diff --git a/lib/Interpreter/InvocationOptions.cpp b/lib/Interpreter/InvocationOptions.cpp index 40e368bcf8..a16bd06b39 100644 --- a/lib/Interpreter/InvocationOptions.cpp +++ b/lib/Interpreter/InvocationOptions.cpp @@ -71,7 +71,6 @@ static const char kNoStdInc[] = "-nostdinc"; InputArgList& Args) { Opts.ErrorOut = Args.hasArg(OPT__errorout); Opts.NoLogo = Args.hasArg(OPT__nologo); - Opts.DumbTerm = Args.hasArg(OPT__dumbterm); Opts.ShowVersion = Args.hasArg(OPT_version); Opts.Help = Args.hasArg(OPT_help); Opts.NoRuntime = Args.hasArg(OPT_noruntime); @@ -147,7 +146,7 @@ void CompilerOptions::Parse(int argc, const char* const argv[], InvocationOptions::InvocationOptions(int argc, const char* const* argv) : - MetaString("."), ErrorOut(false), NoLogo(false), DumbTerm(false), ShowVersion(false), + MetaString("."), ErrorOut(false), NoLogo(false), ShowVersion(false), Help(false), NoRuntime(false) { diff --git a/lib/UserInterface/UserInterface.cpp b/lib/UserInterface/UserInterface.cpp index 455cb6e43f..156249fda7 100644 --- a/lib/UserInterface/UserInterface.cpp +++ b/lib/UserInterface/UserInterface.cpp @@ -98,7 +98,7 @@ namespace cling { UITabCompletion* Completion = new UITabCompletion(m_MetaProcessor->getInterpreter()); TI.SetCompletion(Completion); - if (m_MetaProcessor->getInterpreter().getOptions().DumbTerm) { + if (D->GetTERM() && strstr(D->GetTERM(), "dumb")) { TI.SetIsDumbTerm(true); } diff --git a/lib/UserInterface/textinput/TerminalDisplay.h b/lib/UserInterface/textinput/TerminalDisplay.h index c16a454984..de3ed404f0 100644 --- a/lib/UserInterface/textinput/TerminalDisplay.h +++ b/lib/UserInterface/textinput/TerminalDisplay.h @@ -40,6 +40,8 @@ namespace textinput { void Detach(); void DisplayInfo(const std::vector& Options); bool IsTTY() const { return fIsTTY; } + void SetTERM(const char* TERM) { fTERM = TERM; }; + const char* GetTERM() { return fTERM; }; protected: TerminalDisplay(bool isTTY): @@ -83,6 +85,7 @@ namespace textinput { size_t fWriteLen; // Length of output written. Pos fWritePos; // Current position of writing (temporarily != cursor) char fPrevColor; // currently configured color + const char* fTERM; // terminal type }; } #endif // TEXTINPUT_TERMINALDISPLAY_H diff --git a/lib/UserInterface/textinput/TerminalDisplayUnix.cpp b/lib/UserInterface/textinput/TerminalDisplayUnix.cpp index 291788c5c3..73ed76489b 100644 --- a/lib/UserInterface/textinput/TerminalDisplayUnix.cpp +++ b/lib/UserInterface/textinput/TerminalDisplayUnix.cpp @@ -119,6 +119,7 @@ namespace textinput { TerminalConfigUnix::Get().TIOS()->c_lflag |= ECHOCTL|ECHOKE|ECHOE; #endif const char* TERM = getenv("TERM"); + SetTERM(TERM); if (TERM && strstr(TERM, "256")) { fNColors = 256; } diff --git a/lib/UserInterface/textinput/TerminalDisplayWin.cpp b/lib/UserInterface/textinput/TerminalDisplayWin.cpp index 41cb362360..a465a8db3d 100644 --- a/lib/UserInterface/textinput/TerminalDisplayWin.cpp +++ b/lib/UserInterface/textinput/TerminalDisplayWin.cpp @@ -23,6 +23,7 @@ namespace textinput { TerminalDisplayWin::TerminalDisplayWin(): TerminalDisplay(false), fStartLine(0), fIsAttached(false), fDefaultAttributes(0), fOldCodePage(::GetConsoleOutputCP()) { + SetTerm("win"); DWORD mode; SetIsTTY(::GetConsoleMode(::GetStdHandle(STD_INPUT_HANDLE), &mode) != 0);