1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 00:55:08 +00:00

LibLine: Read configuration from a config file

This commit is contained in:
AnotherTest 2020-08-17 19:13:52 +04:30 committed by Andreas Kling
parent afbeb8f977
commit d0aab41628
3 changed files with 35 additions and 4 deletions

View file

@ -29,6 +29,7 @@
#include <AK/StringBuilder.h> #include <AK/StringBuilder.h>
#include <AK/Utf32View.h> #include <AK/Utf32View.h>
#include <AK/Utf8View.h> #include <AK/Utf8View.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/Event.h> #include <LibCore/Event.h>
#include <LibCore/EventLoop.h> #include <LibCore/EventLoop.h>
#include <LibCore/Notifier.h> #include <LibCore/Notifier.h>
@ -47,6 +48,32 @@ constexpr u32 ctrl(char c) { return c & 0x3f; }
namespace Line { 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) Editor::Editor(Configuration configuration)
: m_configuration(move(configuration)) : m_configuration(move(configuration))
{ {

View file

@ -78,6 +78,8 @@ struct Configuration {
void set(RefreshBehaviour refresh) { refresh_behaviour = refresh; } void set(RefreshBehaviour refresh) { refresh_behaviour = refresh; }
void set(OperationMode mode) { operation_mode = mode; } void set(OperationMode mode) { operation_mode = mode; }
static Configuration from_config(const StringView& libname = "line");
RefreshBehaviour refresh_behaviour { RefreshBehaviour::Lazy }; RefreshBehaviour refresh_behaviour { RefreshBehaviour::Lazy };
OperationMode operation_mode { OperationMode::Unset }; OperationMode operation_mode { OperationMode::Unset };
}; };
@ -178,7 +180,7 @@ public:
const Utf32View buffer_view() const { return { m_buffer.data(), m_buffer.size() }; } const Utf32View buffer_view() const { return { m_buffer.data(), m_buffer.size() }; }
private: private:
explicit Editor(Configuration configuration = {}); explicit Editor(Configuration configuration = Configuration::from_config());
enum VTState { enum VTState {
Free = 1, Free = 1,
@ -365,8 +367,10 @@ private:
HashMap<char, NonnullOwnPtr<KeyCallback>> m_key_callbacks; HashMap<char, NonnullOwnPtr<KeyCallback>> m_key_callbacks;
// TODO: handle signals internally. // TODO: handle signals internally.
struct termios m_termios {}; struct termios m_termios {
struct termios m_default_termios {}; };
struct termios m_default_termios {
};
bool m_was_interrupted { false }; bool m_was_interrupted { false };
bool m_was_resized { false }; bool m_was_resized { false };

View file

@ -176,7 +176,7 @@ int main(int argc, char** argv)
} }
#endif #endif
editor = Line::Editor::construct(Line::Configuration {}); editor = Line::Editor::construct();
auto shell = Shell::construct(); auto shell = Shell::construct();
s_shell = shell.ptr(); s_shell = shell.ptr();