Skip to content

Commit

Permalink
add - doc - Added refresh keybind (ALT + R)
Browse files Browse the repository at this point in the history
Added the refresh feature.

---

If your prompt is ever corrupt, you can refresh it.

---

Type: add
Breaking: False
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Aug 12, 2023
1 parent 6c6cb85 commit 59dfbd7
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Terminaux/Reader/Bindings/BaseBindings/Refresh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

// Terminaux Copyright (C) 2023 Aptivi
//
// This file is part of Terminaux
//
// Terminaux is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Terminaux is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

using System;
using Terminaux.Reader.Tools;
using Terminaux.Base;

namespace Terminaux.Reader.Bindings.BaseBindings
{
internal class Refresh : BaseBinding, IBinding
{
/// <inheritdoc/>
public override ConsoleKeyInfo[] BoundKeys { get; } =
{
new ConsoleKeyInfo('r', ConsoleKey.R, false, true, false),
};

/// <inheritdoc/>
public override bool IsExit => false;

/// <inheritdoc/>
public override void DoAction(TermReaderState state)
{
// Determine if the input prompt text is either overflowing or intentionally placing
// the newlines using the "incomplete sentences" feature, then refresh the input
// prompt.
int longestSentenceLength = ConsoleTools.ActionWindowWidth() - state.settings.RightMargin - state.inputPromptLeft - 1;
string[] wrapped = ConsoleExtensions.GetWrappedSentences(state.InputPromptText, longestSentenceLength);
ConsoleTools.ActionSetCursorPosition(state.settings.LeftMargin, ConsoleTools.ActionCursorTop() - wrapped.Length + 1);
ConsoleTools.ActionWriteString(state.InputPromptText, state.Settings);

// Now, render the current text
string renderedText = state.PasswordMode ? new string(state.settings.PasswordMaskChar, state.currentText.ToString().Length) : state.currentText.ToString();
if (state.OneLineWrap)
{
// We're in the one-line wrap mode!
string[] incompleteSentences = GetWrappedSentences(renderedText, longestSentenceLength, 0);
renderedText = state.OneLineWrap ? GetOneLineWrappedSentenceToRender(incompleteSentences, state) : renderedText;
ConsoleTools.ActionSetCursorPosition(state.InputPromptLeft, state.InputPromptTop);
ConsoleTools.ActionWriteString(renderedText + new string(' ', longestSentenceLength - renderedText.Length), state.settings);
}
else
{
ConsoleTools.ActionSetCursorPosition(state.InputPromptLeft, state.InputPromptTop);
ConsoleTools.ActionWriteString(renderedText + new string(' ', state.CurrentText.Length - state.CurrentTextPos), state.settings);
}
ConsoleTools.ActionSetCursorPosition(state.CurrentCursorPosLeft, state.CurrentCursorPosTop);
}
}
}
1 change: 1 addition & 0 deletions Terminaux/Reader/Bindings/BindingsList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ internal static class BindingsList
new UpAndForwardOneWord(),
new LoAndForwardOneWord(),
new ShowSuggestions(),
new Refresh(),

#if DEBUG
new DebugPos()
Expand Down

0 comments on commit 59dfbd7

Please sign in to comment.