forked from fish-shell/fish-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This introduces a new type features_t that exposes feature flags. The intent is to allow a deprecation/incremental adoption path. This is not a general purpose configuration mechanism, but instead allows for compatibility during the transition as features are added/removed. Each feature has a user-presentable short name and a short description. Their values are tracked in a struct features_t. We start with one feature stderr_nocaret, but it's not hooked up yet.
- Loading branch information
1 parent
7cbc0c3
commit 14f766b
Showing
5 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "config.h" // IWYU pragma: keep | ||
|
||
#include <wchar.h> | ||
#include "future_feature_flags.h" | ||
|
||
/// The set of features applying to this instance. | ||
static features_t global_features; | ||
|
||
const features_t &fish_features() { return global_features; } | ||
|
||
features_t &mutable_fish_features() { return global_features; } | ||
|
||
const features_t::metadata_t features_t::metadata[features_t::flag_count] = { | ||
{stderr_nocaret, L"stderr-nocaret", L"3.0", L"^ no longer redirects stderr"}, | ||
}; | ||
|
||
const struct features_t::metadata_t *features_t::metadata_for(const wchar_t *name) { | ||
assert(name && "null flag name"); | ||
for (const auto &md : metadata) { | ||
if (!wcscmp(name, md.name)) return &md; | ||
} | ||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Flags to enable upcoming features | ||
#ifndef FISH_FUTURE_FEATURE_FLAGS_H | ||
#define FISH_FUTURE_FEATURE_FLAGS_H | ||
|
||
#include <assert.h> | ||
|
||
class features_t { | ||
public: | ||
/// The list of flags. | ||
enum flag_t { | ||
/// Whether ^ is supported for stderr redirection. | ||
stderr_nocaret, | ||
|
||
/// The number of flags. | ||
flag_count | ||
}; | ||
|
||
/// Return whether a flag is set. | ||
bool test(flag_t f) const { | ||
assert(f >= 0 && f < flag_count && "Invalid flag"); | ||
return values[f]; | ||
} | ||
|
||
/// Set a flag. | ||
void set(flag_t f, bool value) { | ||
assert(f >= 0 && f < flag_count && "Invalid flag"); | ||
values[f] = value; | ||
} | ||
|
||
/// Metadata about feature flags. | ||
struct metadata_t { | ||
/// The flag itself. | ||
features_t::flag_t flag; | ||
|
||
/// User-presentable short name of the feature flag. | ||
const wchar_t *name; | ||
|
||
/// Comma-separated list of feature groups. | ||
const wchar_t *groups; | ||
|
||
/// User-presentable description of the feature flag. | ||
const wchar_t *description; | ||
}; | ||
|
||
/// The metadata, indexed by flag. | ||
static const metadata_t metadata[flag_count]; | ||
|
||
/// Return the metadata for a particular name, or nullptr if not found. | ||
static const struct metadata_t *metadata_for(const wchar_t *name); | ||
|
||
private: | ||
/// Values for the flags. | ||
bool values[flag_count] = {}; | ||
}; | ||
|
||
/// Return the global set of features for fish. This is const to prevent accidental mutation. | ||
const features_t &fish_features(); | ||
|
||
/// Return the global set of features for fish, but mutable. In general fish features should be set | ||
/// at startup only. | ||
features_t &mutable_fish_features(); | ||
|
||
#endif |