-
Notifications
You must be signed in to change notification settings - Fork 312
Expand file tree
/
Copy pathTextInput.h
More file actions
113 lines (96 loc) · 3.88 KB
/
Copy pathTextInput.h
File metadata and controls
113 lines (96 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//===--- TextInput.h - Main Interface ---------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the main interface for the TextInput library.
//
// Axel Naumann <axel@cern.ch>, 2011-05-12
//===----------------------------------------------------------------------===//
#ifndef TEXTINPUT_TEXTINPUT_H
#define TEXTINPUT_TEXTINPUT_H
#include <stddef.h>
#include <string>
#include <vector>
namespace textinput {
class Colorizer;
class Display;
class EditorRange;
class FunKey;
class InputData;
class Reader;
class TextInputContext;
class TabCompletion;
// Main interface to textinput library.
class TextInput {
public:
// State of input
enum EReadResult {
kRRNone, // uninitialized
kRRReadEOLDelimiter, // end of line is entered, can take input
kRRCharLimitReached, // SetMaxPendingCharsToRead() of input are read
kRRNoMorePendingInput, // no input available
kRREOF // end of file has been reached
};
TextInput(Reader& reader, Display& display,
const char* histFile = 0);
~TextInput();
// Getters
const TextInputContext* GetContext() const { return fContext; }
bool IsInputMasked() const { return fMasked; }
size_t GetMaxPendingCharsToRead() const { return fMaxChars; }
bool IsReadingAllPendingChars() const { return fMaxChars == (size_t) -1; }
bool IsBlockingUntilEOL() const { return fMaxChars == 0; }
// Setters
void SetPrompt(const char* p);
void MaskInput(bool masked = true) { fMasked = masked; }
void SetColorizer(Colorizer* c);
void SetCompletion(TabCompletion* tc);
void SetFunctionKeyHandler(FunKey* fc);
void SetMaxPendingCharsToRead(size_t nMax) { fMaxChars = nMax; }
void SetReadingAllPendingChars() { fMaxChars = (size_t) -1; }
void SetBlockingUntilEOL() { fMaxChars = 0; }
// Read interface
EReadResult ReadInput();
EReadResult GetReadState() const { return fLastReadResult; }
char GetLastKey() const { return fLastKey; }
const std::string& GetInput();
void TakeInput(std::string& input, bool force = false); // Take and reset input
bool AtEOL() const { return fLastReadResult == kRRReadEOLDelimiter || AtEOF(); }
bool AtEOF() const { return fLastReadResult == kRREOF; }
bool HavePendingInput() const;
// Display interface
void Redraw();
void UpdateDisplay(const EditorRange& r);
void DisplayInfo(const std::vector<std::string>& lines);
void HandleResize();
void GrabInputOutput() const;
void ReleaseInputOutput() const;
// History interface
bool IsAutoHistAddEnabled() const { return fAutoHistAdd; }
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);
void DisplayNewInput(EditorRange& r, size_t& oldCursorPos);
bool fMasked; // whether input should be shown
bool fAutoHistAdd; // whether input should be added to history
char fLastKey; // most recently read key
size_t fMaxChars; // Num chars to read; 0 for blocking, -1 for all available
EReadResult fLastReadResult; // current input state
TextInputContext* fContext; // context object
mutable bool fActive; // whether textinput is controlling input/output
bool fNeedPromptRedraw; // whether the prompt should be redrawn on next attach
};
}
#endif