Skip to content

Commit

Permalink
Merge branch 'FarGroup:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
deep-soft authored Sep 8, 2024
2 parents a4367c9 + b280d1e commit 9701ccc
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 92 deletions.
7 changes: 7 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
--------------------------------------------------------------------------------
drkns 2024-09-05 21:27:14+01:00 - build 6367

1. Minor rendering fixes.

2. Refactoring.

--------------------------------------------------------------------------------
drkns 2024-08-31 13:02:11+01:00 - build 6366

Expand Down
21 changes: 15 additions & 6 deletions far/color_picker_256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,23 @@ static_assert(std::size(grey_control_by_index) == colors::index::grey_count);
static constexpr auto grey_index_by_control = column_major_iota<uint8_t, 4, 6>();
static_assert(std::size(grey_index_by_control) == colors::index::grey_count);

static constexpr uint8_t grey_stripe_mapping[]
static constexpr auto grey_stripe_mapping = []
{
0, 1, 2, 3, 4, 5,
11, 10, 9, 8, 7, 6,
12, 13, 14, 15, 16, 17,
23, 22, 21, 20, 19, 18
};
std::array<uint8_t, colors::index::grey_count> Result;

for (auto& i: Result)
{
const auto Index = &i - Result.data();
const auto RowSize = 6;
const auto Row = Index / RowSize;

i = Row & 1?
Row * RowSize + RowSize - 1 - Index % RowSize :
Index;
}

return Result;
}();
static_assert(std::size(grey_stripe_mapping) == colors::index::grey_count);

static bool is_rgb(uint8_t const Color)
Expand Down
81 changes: 45 additions & 36 deletions far/configdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,33 +238,29 @@ void serialise_blob(tinyxml::XMLElement& e, bytes_view const Value)
SetAttribute(e, "value", base64::encode(Value));
}

bool deserialise_value(char const* Type, char const* Value, auto const& Setter)
bool deserialise_value(std::string_view const Type, char const* Value, auto const& Setter)
{
if (!strcmp(Type, "qword"))
if (Type == "qword"sv)
{
if (Value)
Setter(strtoull(Value, nullptr, 16));
Setter(strtoull(Value, nullptr, 16));
return true;
}

if (!strcmp(Type, "text"))
if (Type == "text"sv)
{
if (Value)
Setter(encoding::utf8::get_chars(Value));
Setter(encoding::utf8::get_chars(Value));
return true;
}

if (!strcmp(Type, "base64"))
if (Type == "base64"sv)
{
if (Value)
Setter(base64::decode(Value));
Setter(base64::decode(Value));
return true;
}

if (!strcmp(Type, "hex"))
if (Type == "hex"sv)
{
if (Value)
Setter(HexStringToBlob(encoding::utf8::get_chars(Value)));
Setter(HexStringToBlob(encoding::utf8::get_chars(Value)));
return true;
}

Expand Down Expand Up @@ -311,14 +307,14 @@ class iGeneralConfigDb: public GeneralConfig, public sqlite_boilerplate
private:
static void Initialise(const db_initialiser& Db)
{
static const std::string_view Schema[]
static constexpr std::string_view Schema[]
{
"CREATE TABLE IF NOT EXISTS general_config(key TEXT NOT NULL, name TEXT NOT NULL, value BLOB, PRIMARY KEY (key, name));"sv,
};

Db.Exec(Schema);

static const stmt_init<statement_id> Statements[]
static constexpr stmt_init<statement_id> Statements[]
{
{ stmtSetValue, "REPLACE INTO general_config VALUES (?1,?2,?3);"sv },
{ stmtGetValue, "SELECT value FROM general_config WHERE key=?1 AND name=?2;"sv },
Expand Down Expand Up @@ -426,11 +422,19 @@ class iGeneralConfigDb: public GeneralConfig, public sqlite_boilerplate
for(const auto& e: xml_enum(Representation.Root().FirstChildElement(GetKeyName()), "setting"))
{
const auto key = e.Attribute("key");
if (!key)
continue;

const auto name = e.Attribute("name");
if (!name)
continue;

const auto type = e.Attribute("type");
const auto value = e.Attribute("value");
if (!type)
continue;

if (!key || !name || !type || !value)
const auto value = e.Attribute("value");
if (!value)
continue;

const auto Key = encoding::utf8::get_chars(key);
Expand Down Expand Up @@ -535,7 +539,7 @@ class HierarchicalConfigDb: public async_delete_impl, public HierarchicalConfig,

Db.add_numeric_collation();

static const std::string_view Schema[]
static constexpr std::string_view Schema[]
{
"CREATE TABLE IF NOT EXISTS table_keys(id INTEGER PRIMARY KEY, parent_id INTEGER NOT NULL, name TEXT NOT NULL, description TEXT, FOREIGN KEY(parent_id) REFERENCES table_keys(id) ON UPDATE CASCADE ON DELETE CASCADE, UNIQUE (parent_id,name));"sv,
"CREATE TABLE IF NOT EXISTS table_values(key_id INTEGER NOT NULL, name TEXT NOT NULL, value BLOB, FOREIGN KEY(key_id) REFERENCES table_keys(id) ON UPDATE CASCADE ON DELETE CASCADE, PRIMARY KEY (key_id, name), CHECK (key_id <> 0));"sv,
Expand All @@ -545,7 +549,7 @@ class HierarchicalConfigDb: public async_delete_impl, public HierarchicalConfig,

Db.Exec(Schema);

static const stmt_init<statement_id> Statements[]
static constexpr stmt_init<statement_id> Statements[]
{
{ stmtCreateKey, "INSERT OR IGNORE INTO table_keys VALUES (NULL,?1,?2,NULL);"sv },
{ stmtFindKey, "SELECT id FROM table_keys WHERE parent_id=?1 AND name=?2 AND id<>0;"sv },
Expand Down Expand Up @@ -781,12 +785,15 @@ class HierarchicalConfigDb: public async_delete_impl, public HierarchicalConfig,
for (const auto& e: xml_enum(key, "value"))
{
const auto name = e.Attribute("name");
const auto type = e.Attribute("type");
const auto value = e.Attribute("value");
if (!name)
continue;

if (!name || !type)
const auto type = e.Attribute("type");
if (!type)
continue;

const auto value = e.Attribute("value");

const auto Name = encoding::utf8::get_chars(name);

if (!deserialise_value(type, value, [&](auto const& Value){ SetValue(Key, Name, Value); }))
Expand Down Expand Up @@ -940,14 +947,14 @@ class ColorsConfigDb final: public ColorsConfig, public sqlite_boilerplate
{
Db.add_numeric_collation();

static const std::string_view Schema[]
static constexpr std::string_view Schema[]
{
"CREATE TABLE IF NOT EXISTS colors(name TEXT NOT NULL PRIMARY KEY, value BLOB);"sv,
};

Db.Exec(Schema);

static const stmt_init<statement_id> Statements[]
static constexpr stmt_init<statement_id> Statements[]
{
{ stmtSetValue, "REPLACE INTO colors VALUES (?1,?2);"sv },
{ stmtGetValue, "SELECT value FROM colors WHERE name=?1;"sv },
Expand Down Expand Up @@ -1031,15 +1038,15 @@ class AssociationsConfigDb final: public AssociationsConfig, public sqlite_boile
{
Db.EnableForeignKeysConstraints();

static const std::string_view Schema[]
static constexpr std::string_view Schema[]
{
"CREATE TABLE IF NOT EXISTS filetypes(id INTEGER PRIMARY KEY, weight INTEGER NOT NULL, mask TEXT, description TEXT);"sv,
"CREATE TABLE IF NOT EXISTS commands(ft_id INTEGER NOT NULL, type INTEGER NOT NULL, enabled INTEGER NOT NULL, command TEXT, FOREIGN KEY(ft_id) REFERENCES filetypes(id) ON UPDATE CASCADE ON DELETE CASCADE, PRIMARY KEY (ft_id, type));"sv,
};

Db.Exec(Schema);

static const stmt_init<statement_id> Statements[]
static constexpr stmt_init<statement_id> Statements[]
{
{ stmtReorder, "UPDATE filetypes SET weight=weight+1 WHERE weight>(CASE ?1 WHEN 0 THEN 0 ELSE (SELECT weight FROM filetypes WHERE id=?1) END);"sv },
{ stmtAddType, "INSERT INTO filetypes VALUES (NULL,(CASE ?1 WHEN 0 THEN 1 ELSE (SELECT weight FROM filetypes WHERE id=?1)+1 END),?2,?3);"sv },
Expand Down Expand Up @@ -1292,7 +1299,7 @@ class PluginsCacheConfigDb final: public PluginsCacheConfig, public sqlite_boile
Db.SetWALJournalingMode();
Db.EnableForeignKeysConstraints();

static const std::string_view Schema[]
static constexpr std::string_view Schema[]
{
"CREATE TABLE IF NOT EXISTS cachename(id INTEGER PRIMARY KEY, name TEXT NOT NULL UNIQUE);"sv,
"CREATE TABLE IF NOT EXISTS preload(cid INTEGER NOT NULL PRIMARY KEY, enabled INTEGER NOT NULL, FOREIGN KEY(cid) REFERENCES cachename(id) ON UPDATE CASCADE ON DELETE CASCADE);"sv,
Expand All @@ -1311,7 +1318,7 @@ class PluginsCacheConfigDb final: public PluginsCacheConfig, public sqlite_boile

Db.Exec(Schema);

static const stmt_init<statement_id> Statements[]
static constexpr stmt_init<statement_id> Statements[]
{
{ stmtCreateCache, "INSERT INTO cachename VALUES (NULL,?1);"sv },
{ stmtFindCacheName, "SELECT id FROM cachename WHERE name=?1;"sv },
Expand Down Expand Up @@ -1623,14 +1630,14 @@ class PluginsHotkeysConfigDb final: public PluginsHotkeysConfig, public sqlite_b
private:
static void Initialise(const db_initialiser& Db)
{
static const std::string_view Schema[]
static constexpr std::string_view Schema[]
{
"CREATE TABLE IF NOT EXISTS pluginhotkeys(pluginkey TEXT NOT NULL, menuguid TEXT NOT NULL, type INTEGER NOT NULL, hotkey TEXT, PRIMARY KEY(pluginkey, menuguid, type));"sv,
};

Db.Exec(Schema);

static const stmt_init<statement_id> Statements[]
static constexpr stmt_init<statement_id> Statements[]
{
{ stmtGetHotkey, "SELECT hotkey FROM pluginhotkeys WHERE pluginkey=?1 AND menuguid=?2 AND type=?3;"sv },
{ stmtSetHotkey, "REPLACE INTO pluginhotkeys VALUES (?1,?2,?3,?4);"sv },
Expand Down Expand Up @@ -1738,11 +1745,13 @@ class PluginsHotkeysConfigDb final: public PluginsHotkeysConfig, public sqlite_b
DelHotkey(Key, *Uuid, Type);
};

if (!strcmp(stype, "drive"))
std::string_view const TypeStr(stype);

if (TypeStr == "drive"sv)
ProcessHotkey(hotkey_type::drive_menu);
else if (!strcmp(stype, "config"))
else if (TypeStr == "config"sv)
ProcessHotkey(hotkey_type::config_menu);
else if (!strcmp(stype, "plugins"))
else if (TypeStr == "plugins"sv)
ProcessHotkey(hotkey_type::plugins_menu);
}

Expand Down Expand Up @@ -1900,7 +1909,7 @@ class HistoryConfigCustom: public HistoryConfig, public sqlite_boilerplate

Db.add_nocase_collation();

static const std::string_view Schema[]
static constexpr std::string_view Schema[]
{
//command,view,edit,folder,dialog history
"CREATE TABLE IF NOT EXISTS history(id INTEGER PRIMARY KEY, kind INTEGER NOT NULL, key TEXT NOT NULL, type INTEGER NOT NULL, lock INTEGER NOT NULL, name TEXT NOT NULL, time INTEGER NOT NULL, guid TEXT NOT NULL, file TEXT NOT NULL, data TEXT NOT NULL);"sv,
Expand All @@ -1924,7 +1933,7 @@ class HistoryConfigCustom: public HistoryConfig, public sqlite_boilerplate
// Must be after reindex
Db.EnableForeignKeysConstraints();

static const stmt_init<statement_id> Statements[]
static constexpr stmt_init<statement_id> Statements[]
{
{ stmtEnum, "SELECT id, name, type, lock, time, guid, file, data FROM history WHERE kind=?1 AND key=?2 AND (?3 OR name COLLATE NOCASE =?4) ORDER BY time;"sv },
{ stmtEnumDesc, "SELECT id, name, type, lock, time, guid, file, data FROM history WHERE kind=?1 AND key=?2 AND (?3 OR name COLLATE NOCASE =?4) ORDER BY lock DESC, time DESC;"sv },
Expand Down Expand Up @@ -2388,7 +2397,7 @@ void config_provider::TryImportDatabase(representable& p, const char* NodeName,
for (const auto& i: xml_enum(root.FirstChildElement("pluginsconfig"), "plugin"))
{
const auto Uuid = i.Attribute("guid");
if (Uuid && 0 == strcmp(Uuid, NodeName))
if (Uuid && !std::strcmp(Uuid, NodeName))
{
m_TemplateSource->SetRoot(&const_cast<tinyxml::XMLElement&>(i));
p.Import(*m_TemplateSource);
Expand Down
3 changes: 1 addition & 2 deletions far/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ namespace console_detail
(
encoding::utf16::is_high_surrogate(Cell.Char) ||
// FFFD can be wide too
(Cell.Char == encoding::replace_char && char_width::is_wide(encoding::replace_char))
(Cell.Char == encoding::replace_char && Cell.Reserved1 <= std::numeric_limits<wchar_t>::max() && char_width::is_wide(encoding::replace_char))
)
)
{
Expand Down Expand Up @@ -1952,7 +1952,6 @@ namespace console_detail
ConsoleBuffer.reserve(SubRect.width() * SubRect.height());

foreign_blocks_list ForeignBlocksList;
std::optional<rectangle> ForeignBlock;

if (char_width::is_enabled())
{
Expand Down
5 changes: 2 additions & 3 deletions far/macroapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2296,11 +2296,10 @@ void FarMacroApi::farcfggetFunc() const
// V=Far.GetConfig(Key.Name)
void FarMacroApi::fargetconfigFunc() const
{
const wchar_t *Keyname = (mData->Count >= 1 && mData->Values[0].Type==FMVT_STRING) ?
const auto Keyname = (mData->Count >= 1 && mData->Values[0].Type==FMVT_STRING) ?
mData->Values[0].String : L"";

const auto Dot = wcsrchr(Keyname, L'.');
if (Dot)
if (const auto Dot = std::wcsrchr(Keyname, L'.'))
{
const string_view Key(Keyname, Dot - Keyname);

Expand Down
Loading

0 comments on commit 9701ccc

Please sign in to comment.