summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-08-17 19:13:52 +0430
committerAndreas Kling <kling@serenityos.org>2020-08-18 12:07:32 +0200
commitd0aab41628719e0979cc916e136bd3f37e41435d (patch)
treef1ee8cca66ce1f6698e454ae57febc783d213b32
parentafbeb8f977ba5c009e88f702242bba678486480f (diff)
downloadserenity-d0aab41628719e0979cc916e136bd3f37e41435d.zip
LibLine: Read configuration from a config file
-rw-r--r--Libraries/LibLine/Editor.cpp27
-rw-r--r--Libraries/LibLine/Editor.h10
-rw-r--r--Shell/main.cpp2
3 files changed, 35 insertions, 4 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp
index c83ddc403c..4b4108289b 100644
--- a/Libraries/LibLine/Editor.cpp
+++ b/Libraries/LibLine/Editor.cpp
@@ -29,6 +29,7 @@
#include <AK/StringBuilder.h>
#include <AK/Utf32View.h>
#include <AK/Utf8View.h>
+#include <LibCore/ConfigFile.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Notifier.h>
@@ -47,6 +48,32 @@ constexpr u32 ctrl(char c) { return c & 0x3f; }
namespace Line {
+Configuration Configuration::from_config(const StringView& libname)
+{
+ Configuration configuration;
+ auto config_file = Core::ConfigFile::get_for_lib(libname);
+
+ // Read behaviour options.
+ auto refresh = config_file->read_entry("behaviour", "refresh", "lazy");
+ auto operation = config_file->read_entry("behaviour", "operation_mode");
+
+ if (refresh.equals_ignoring_case("lazy"))
+ configuration.set(Configuration::Lazy);
+ else if (refresh.equals_ignoring_case("eager"))
+ configuration.set(Configuration::Eager);
+
+ if (operation.equals_ignoring_case("full"))
+ configuration.set(Configuration::OperationMode::Full);
+ else if (operation.equals_ignoring_case("noescapesequences"))
+ configuration.set(Configuration::OperationMode::NoEscapeSequences);
+ else if (operation.equals_ignoring_case("noninteractive"))
+ configuration.set(Configuration::OperationMode::NonInteractive);
+ else
+ configuration.set(Configuration::OperationMode::Unset);
+
+ return configuration;
+}
+
Editor::Editor(Configuration configuration)
: m_configuration(move(configuration))
{
diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h
index c7d56ae8b6..67ef3a0c8c 100644
--- a/Libraries/LibLine/Editor.h
+++ b/Libraries/LibLine/Editor.h
@@ -78,6 +78,8 @@ struct Configuration {
void set(RefreshBehaviour refresh) { refresh_behaviour = refresh; }
void set(OperationMode mode) { operation_mode = mode; }
+ static Configuration from_config(const StringView& libname = "line");
+
RefreshBehaviour refresh_behaviour { RefreshBehaviour::Lazy };
OperationMode operation_mode { OperationMode::Unset };
};
@@ -178,7 +180,7 @@ public:
const Utf32View buffer_view() const { return { m_buffer.data(), m_buffer.size() }; }
private:
- explicit Editor(Configuration configuration = {});
+ explicit Editor(Configuration configuration = Configuration::from_config());
enum VTState {
Free = 1,
@@ -365,8 +367,10 @@ private:
HashMap<char, NonnullOwnPtr<KeyCallback>> m_key_callbacks;
// TODO: handle signals internally.
- struct termios m_termios {};
- struct termios m_default_termios {};
+ struct termios m_termios {
+ };
+ struct termios m_default_termios {
+ };
bool m_was_interrupted { false };
bool m_was_resized { false };
diff --git a/Shell/main.cpp b/Shell/main.cpp
index b50c250ef5..f8671a9fb8 100644
--- a/Shell/main.cpp
+++ b/Shell/main.cpp
@@ -176,7 +176,7 @@ int main(int argc, char** argv)
}
#endif
- editor = Line::Editor::construct(Line::Configuration {});
+ editor = Line::Editor::construct();
auto shell = Shell::construct();
s_shell = shell.ptr();