Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a command line flag and associated code to support dumb terminals #99

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Interpreter/InvocationOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ void CompilerOptions::Parse(int argc, const char* const argv[],
}

InvocationOptions::InvocationOptions(int argc, const char* const* argv) :

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the changes in this file from this PR?

MetaString("."), ErrorOut(false), NoLogo(false), ShowVersion(false),
Help(false), NoRuntime(false) {


ArrayRef<const char *> ArgStrings(argv, argv + argc);
unsigned MissingArgIndex, MissingArgCount;
std::unique_ptr<OptTable> Opts(CreateClingOptTable());
Expand Down
3 changes: 3 additions & 0 deletions lib/UserInterface/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ namespace cling {
UITabCompletion* Completion =
new UITabCompletion(m_MetaProcessor->getInterpreter());
TI.SetCompletion(Completion);
if (D->GetTERM() && strstr(D->GetTERM(), "dumb")) {
TI.SetIsDumbTerm(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be done inside textinput itself? See below...

}

std::string Line;
std::string Prompt("[cling]$ ");
Expand Down
3 changes: 3 additions & 0 deletions lib/UserInterface/textinput/TerminalDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace textinput {
void Detach();
void DisplayInfo(const std::vector<std::string>& Options);
bool IsTTY() const { return fIsTTY; }
void SetTERM(const char* TERM) { fTERM = TERM; };
const char* GetTERM() { return fTERM; };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These interfaces (nor the data member) should not be needed, see below. Instead we'd need an IsDumb().


protected:
TerminalDisplay(bool isTTY):
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/UserInterface/textinput/TerminalDisplayUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ namespace textinput {
TerminalConfigUnix::Get().TIOS()->c_lflag |= ECHOCTL|ECHOKE|ECHOE;
#endif
const char* TERM = getenv("TERM");
SetTERM(TERM);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If TERM is "dumb", the dumb flag on the TerminalDisplay base should be set.

if (TERM && strstr(TERM, "256")) {
fNColors = 256;
}
Expand Down
1 change: 1 addition & 0 deletions lib/UserInterface/textinput/TerminalDisplayWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 9 additions & 4 deletions lib/UserInterface/textinput/TextInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
namespace textinput {
TextInput::TextInput(Reader& reader, Display& display,
const char* HistFile /* = 0 */):
fIsDumbTerm(false),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that a property of the TerminalDisplay? I'd prefer to have the interface there.

fMasked(false),
fAutoHistAdd(true),
fLastKey(0),
Expand Down Expand Up @@ -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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if should test the display of the current iteration: if it's dumb, don't call NotifyResetInput..

}

ReleaseInputOutput();

Expand Down Expand Up @@ -124,7 +127,9 @@ namespace textinput {
|| (*iR)->HaveBufferedInput()) {
if ((*iR)->ReadInput(nRead, in)) {
ProcessNewInput(in, R);
DisplayNewInput(R, OldCursorPos);
if (!IsDumbTerm()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move that if into DisplayNewInput, testing the dumbness of the display.

DisplayNewInput(R, OldCursorPos);
}
if (fLastReadResult == kRREOF
|| fLastReadResult == kRRReadEOLDelimiter)
break;
Expand Down
7 changes: 7 additions & 0 deletions lib/UserInterface/textinput/TextInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should all be moved to TerminalDisplay.


private:
void EmitSignal(char c, EditorRange& r);
void ProcessNewInput(const InputData& in, EditorRange& r);
Expand Down