Skip to content

Commit

Permalink
Merge pull request #1479 from contour-terminal/improvement/early_exit…
Browse files Browse the repository at this point in the history
…_config

Implement early exit threshold config entry
  • Loading branch information
christianparpart committed Mar 1, 2024
2 parents df4a80b + 0c29cb5 commit d258dd9
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 13 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ jobs:
arch="${{ matrix.arch }}"
echo "PLATFORM=${arch%% *}" >> "$GITHUB_OUTPUT"
echo "ARCH=${arch##* }" >> "$GITHUB_OUTPUT"
- name: "update APT database"
run: sudo apt -q update
- name: Installing xmllint for ci-set-vars
run: sudo apt -qy install libxml2-utils
- name: set environment variables
Expand Down Expand Up @@ -245,6 +247,8 @@ jobs:
arch="${{ matrix.arch }}"
echo "PLATFORM=${arch%% *}" >> "$GITHUB_OUTPUT"
echo "ARCH=${arch##* }" >> "$GITHUB_OUTPUT"
- name: "update APT database"
run: sudo apt -q update
- name: Installing xmllint for ci-set-vars
run: sudo apt -qy install libxml2-utils
- name: set environment variables
Expand Down Expand Up @@ -1169,6 +1173,8 @@ jobs:
needs: [package_for_Ubuntu]
steps:
- uses: actions/checkout@v3
- name: "update APT database"
run: sudo apt -q update
- name: Installing xmllint for ci-set-vars
run: sudo apt -qy install libxml2-utils
- name: set environment variables
Expand All @@ -1190,6 +1196,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: "update APT database"
run: sudo apt -q update
- name: Installing xmllint for ci-set-vars.sh and check-release.sh
run: sudo apt -qy install libxml2-utils
- name: set variables
Expand Down Expand Up @@ -1220,6 +1228,8 @@ jobs:
discussions: write
steps:
- uses: actions/checkout@v3
- name: "update APT database"
run: sudo apt -q update
- name: Installing xmllint for ci-set-vars
run: sudo apt -qy install libxml2-utils
- name: set variables
Expand Down
4 changes: 3 additions & 1 deletion docs/configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ option specifies the default PTY read buffer size in bytes. It is an advanced op
option sets the size in bytes per PTY Buffer Object. It is an advanced option for internal storage and should be changed carefully. The default value is `1048576`. <br/>
### `default_profile`
option determines the default profile to use in the terminal. <br/>
`spawn_new_process`
### 'early_exit_threshold'
option determines the early threshold time. If contour atempts to close earlier than specified threshold, additional message will be printed that contour terminated too early and additional key press is required to close contour. <br/>
### `spawn_new_process`
flag determines whether a new process should be spawned when creating a new terminal. The default value is `false`. <br/>
### `reflow_on_resize`
option controls whether or not the lines in the terminal should be reflowed when a resize event occurs. The default value is `true`. <br/>
Expand Down
1 change: 1 addition & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<release version="0.4.4" urgency="medium" type="development">
<description>
<ul>
<li>Adds 'early_exit_threshold' config option (#1460)</li>
<li>Add ability to customize the indicator statusline through configuration (#687)</li>
<li>Add generation of config file from internal state (#1282)</li>
<li>Add SGRSAVE and SGRRESTORE VT sequences to save and restore SGR state (They intentionally conflict with XTPUSHSGR and XTPOPSGR)</li>
Expand Down
2 changes: 2 additions & 0 deletions src/contour/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ void YAMLConfigReader::load(Config& c)
loadFromEntry("pty_buffer_size", c.ptyBufferObjectSize);
loadFromEntry("images.sixel_register_count", c.maxImageColorRegisters);
loadFromEntry("live_config", c.live);
loadFromEntry("early_exit_threshold", c.earlyExitThreshold);
loadFromEntry("spawn_new_process", c.spawnNewProcess);
loadFromEntry("images.sixe_scrolling", c.sixelScrolling);
loadFromEntry("reflow_on_resize", c.reflowOnResize);
Expand Down Expand Up @@ -1848,6 +1849,7 @@ std::string YAMLConfigWriter::createString(Config const& c)
process(c.ptyReadBufferSize);
process(c.ptyBufferObjectSize);
process(c.defaultProfileName);
process(c.earlyExitThreshold);
process(c.spawnNewProcess);
process(c.reflowOnResize);
process(c.bypassMouseProtocolModifiers);
Expand Down
3 changes: 3 additions & 0 deletions src/contour/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,9 @@ struct Config
ConfigEntry<vtbackend::Modifiers, documentation::MouseBlockSelectionModifiers>
mouseBlockSelectionModifiers { vtbackend::Modifier::Control };
ConfigEntry<InputMappings, documentation::InputMappings> inputMappings { defaultInputMappings };
ConfigEntry<unsigned, documentation::EarlyExitThreshold> earlyExitThreshold {
documentation::DefaultEarlyExitThreshold
};
ConfigEntry<bool, documentation::SpawnNewProcess> spawnNewProcess { false };
ConfigEntry<bool, documentation::SixelScrolling> sixelScrolling { true };
ConfigEntry<vtbackend::ImageSize, documentation::MaxImageSize> maxImageSize { { vtpty::Width { 0 },
Expand Down
7 changes: 7 additions & 0 deletions src/contour/ConfigDocumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ constexpr StringLiteral PTYBufferObjectSize {
};

constexpr StringLiteral ReflowOnResize {
"\n"
"{comment} Whether or not to reflow the lines on terminal resize events. \n"
"reflow_on_resize: {} \n"
};
Expand Down Expand Up @@ -743,10 +744,16 @@ constexpr StringLiteral InputMappings {
};

constexpr StringLiteral SpawnNewProcess {
"\n"
"{comment} Flag to determine whether to spawn new process or not when creating new terminal \n"
"spawn_new_process: {} \n"
};

constexpr unsigned DefaultEarlyExitThreshold = 5u;
constexpr StringLiteral EarlyExitThreshold { "\n"
"{comment} Time in seconds to check for early threshold \n"
"early_exit_threshold: {} \n" };

constexpr StringLiteral SixelScrolling { "{comment} Enable or disable sixel scrolling (SM/RM ?80 default) \n"
"sixel_scrolling: {} \n" };

Expand Down
14 changes: 12 additions & 2 deletions src/contour/ContourGuiApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ crispy::cli::command ContourGuiApp::parameterDefinition() const
"Dumps internal state at exit into the given directory. This is for debugging contour.",
"PATH" },
CLI::option { "early-exit-threshold",
CLI::value { 6u },
CLI::value { -1 },
"If the spawned process exits earlier than the given threshold seconds, an "
"error message will be printed and the window not closed immediately." },
CLI::option { "working-directory",
Expand Down Expand Up @@ -149,7 +149,17 @@ crispy::cli::command ContourGuiApp::parameterDefinition() const

std::chrono::seconds ContourGuiApp::earlyExitThreshold() const
{
return std::chrono::seconds(parameters().get<unsigned>("contour.terminal.early-exit-threshold"));
auto const configThreshold = config().earlyExitThreshold.value();
auto const parameterThreshold = parameters().get<int>("contour.terminal.early-exit-threshold");

// default threshold is config::documentation::DefaultEarlyExitThreshold seconds
if (parameterThreshold >= 0)
return std::chrono::seconds(parameterThreshold);

if (configThreshold != config::documentation::DefaultEarlyExitThreshold)
return std::chrono::seconds(configThreshold);

return std::chrono::seconds(config::documentation::DefaultEarlyExitThreshold);
}

string ContourGuiApp::profileName() const
Expand Down
19 changes: 9 additions & 10 deletions src/contour/TerminalSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ void TerminalSession::mainLoop()
}

sessionLog()("Event loop terminating (PTY {}).", _terminal.device().isClosed() ? "closed" : "open");
onClosed();
}

void TerminalSession::terminate()
Expand Down Expand Up @@ -572,15 +571,6 @@ void TerminalSession::notify(string_view title, string_view content)
void TerminalSession::onClosed()
{
auto const _ = std::scoped_lock { _onClosedMutex };
auto isClosedAlready = _onClosedHandled.load();
if (isClosedAlready || !_onClosedHandled.compare_exchange_weak(isClosedAlready, true))
{
sessionLog()("onClosed called: thread {}, display {}", crispy::threadName(), _display ? "yes" : "no");
if (_display)
_display->closeDisplay();
return;
}

sessionLog()("Terminal device closed (thread {})", crispy::threadName());

if (!_terminal.device().isClosed())
Expand Down Expand Up @@ -628,6 +618,15 @@ void TerminalSession::onClosed()
return;
}

auto isClosedAlready = _onClosedHandled.load();
if (isClosedAlready || !_onClosedHandled.compare_exchange_weak(isClosedAlready, true))
{
sessionLog()("onClosed called: thread {}, display {}", crispy::threadName(), _display ? "yes" : "no");
if (_display)
_display->closeDisplay();
return;
}

if (_app.dumpStateAtExit().has_value())
inspect();
else if (_display)
Expand Down
3 changes: 3 additions & 0 deletions src/contour/contour.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ pty_buffer_size: 1048576

default_profile: main

# Time in seconds to check for early threshold
early_exit_threshold: 5

# Flag to determine whether to spawn new process or not when creating new terminal
# Default: false
spawn_new_process: false
Expand Down

0 comments on commit d258dd9

Please sign in to comment.