-
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.
--- We've added a new wrapped writer that uses the text viewer interactive TUI. --- Type: add Breaking: False Doc Required: True Backport Required: False Part: 1/1
- Loading branch information
Showing
5 changed files
with
205 additions
and
10 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...ate/Terminaux.Console/Fixtures/Cases/Inputs/CJK/TestTextViewerFullscreenInteractiveCjk.cs
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,44 @@ | ||
// | ||
// Terminaux Copyright (C) 2023-2025 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 Terminaux.Writer.ConsoleWriters; | ||
|
||
namespace Terminaux.Console.Fixtures.Cases.Inputs.CJK | ||
{ | ||
internal class TestTextViewerFullscreenInteractiveCjk : IFixture | ||
{ | ||
public FixtureCategory Category => FixtureCategory.InputCjk; | ||
|
||
public void RunFixture() | ||
{ | ||
string toBeEdited = | ||
""" | ||
我们已经删除了使用 mod 部件来组织多个同名的 mod,因为当 mod 只由单个源代码文件(Visual Basic 或 C#) | ||
组成时,它们是相关的,并且大型 mod 将使用多个源代码文件进行分组,这些源代码文件相互连接。 互相运作。 | ||
某些版本之前,我们删除了基于源代码的 mod,并依赖 mod 开发人员制作 .DLL 版本,以确保它们获得最大的灵 | ||
活性。 由于其刚性,此功能不会再出现。 Nitrocid KS 的所有 API v3.0 之前的版本(包括 0.0.24.x)都以 KS | ||
作为其根命名空间,因为当时的名称是 Kernel Simulator。 我们给这个应用程序命名为 Nitrocid KS,内核名称 | ||
已更改为 Nitrocid Kernel。 因此,根命名空间已从 KS 更改为 Nitrocid,以便与应用程序品牌更加一致。 由于 | ||
历史原因,一些重大变更注释仍然使用 KS 根命名空间,不应修改它们,因为它们列出了上一个版本和下一个版本之 | ||
间发生的更改历史记录。 您必须更新导入以指向新的根命名空间。 | ||
"""; | ||
WrappedWriter.WriteWrapped(toBeEdited); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
private/Terminaux.Console/Fixtures/Cases/Inputs/TestTextViewerFullscreenInteractive.cs
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,53 @@ | ||
// | ||
// Terminaux Copyright (C) 2023-2025 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 Terminaux.Writer.ConsoleWriters; | ||
|
||
namespace Terminaux.Console.Fixtures.Cases.Inputs | ||
{ | ||
internal class TestTextViewerFullscreenInteractive : IFixture | ||
{ | ||
public FixtureCategory Category => FixtureCategory.Input; | ||
|
||
public void RunFixture() | ||
{ | ||
string toBeEdited = | ||
""" | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut | ||
labore et dolore magna aliqua. Quam lacus suspendisse faucibus interdum. Fermentum odio eu | ||
feugiat pretium nibh ipsum consequat nisl. Purus in mollis nunc sed id semper. Ultrices sagittis | ||
orci a scelerisque purus. Malesuada nunc vel risus commodo viverra maecenas accumsan lacus vel. | ||
Nibh tortor id aliquet lectus proin. Mus mauris vitae ultricies leo integer malesuada nunc vel. | ||
Proin fermentum leo vel orci porta non pulvinar. Nulla posuere sollicitudin aliquam ultrices | ||
sagittis orci a scelerisque. Lacus vel facilisis volutpat est. Porta lorem mollis aliquam ut | ||
porttitor leo. Feugiat scelerisque varius morbi enim nunc faucibus a pellentesque sit. A erat | ||
nam at lectus. Semper risus in hendrerit gravida rutrum. Aliquet enim tortor at auctor urna nunc. | ||
Eget nunc scelerisque viverra mauris in. Augue lacus viverra vitae congue eu consequat ac. Non | ||
odio euismod lacinia at quis risus. Ullamcorper sit amet risus nullam. Malesuada fames ac turpis | ||
egestas. Odio ut sem nulla pharetra diam sit. Viverra ipsum nunc aliquet bibendum enim facilisis | ||
gravida. Urna neque viverra justo nec ultrices dui sapien eget mi. Donec massa sapien faucibus et | ||
molestie ac feugiat sed. Potenti nullam ac tortor vitae purus faucibus ornare suspendisse sed. | ||
Eleifend mi in nulla posuere sollicitudin aliquam ultrices sagittis orci. Arcu cursus vitae | ||
congue mauris. Odio euismod lacinia at quis risus sed vulputate odio ut. Quis enim lobortis | ||
scelerisque fermentum dui faucibus in ornare quam. | ||
"""; | ||
WrappedWriter.WriteWrapped(toBeEdited); | ||
} | ||
} | ||
} |
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,91 @@ | ||
// | ||
// Terminaux Copyright (C) 2023-2025 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 System.Diagnostics; | ||
using System.Linq; | ||
using Terminaux.Base; | ||
using Terminaux.Base.Extensions; | ||
using Terminaux.Colors; | ||
using Terminaux.Inputs.Styles.Editor; | ||
using Textify.General; | ||
|
||
namespace Terminaux.Writer.ConsoleWriters | ||
{ | ||
/// <summary> | ||
/// Wrapped writer similar to <c>less</c> and <c>more</c> commands on Unix | ||
/// </summary> | ||
public static class WrappedWriter | ||
{ | ||
/// <summary> | ||
/// Writes the text in a pager similar to <c>less</c> and <c>more</c> commands on Unix | ||
/// </summary> | ||
/// <param name="text">Text to write. If it's shorter than the console height, it just prints the text</param> | ||
/// <param name="force">Forces the text viewer to open, even if the text doesn't exceed the console height</param> | ||
/// <param name="args">Arguments to format the text</param> | ||
public static void WriteWrapped(string text, bool force = false, params object?[]? args) => | ||
WriteWrapped(text, ColorTools.currentForegroundColor, force, args); | ||
|
||
/// <summary> | ||
/// Writes the text in a pager similar to <c>less</c> and <c>more</c> commands on Unix | ||
/// </summary> | ||
/// <param name="text">Text to write. If it's shorter than the console height, it just prints the text</param> | ||
/// <param name="force">Forces the text viewer to open, even if the text doesn't exceed the console height</param> | ||
/// <param name="color">A color that will be changed to.</param> | ||
/// <param name="args">Arguments to format the text</param> | ||
public static void WriteWrapped(string text, Color color, bool force = false, params object?[]? args) => | ||
WriteWrapped(text, color, ColorTools.currentBackgroundColor, force, args); | ||
|
||
/// <summary> | ||
/// Writes the text in a pager similar to <c>less</c> and <c>more</c> commands on Unix | ||
/// </summary> | ||
/// <param name="text">Text to write. If it's shorter than the console height, it just prints the text</param> | ||
/// <param name="force">Forces the text viewer to open, even if the text doesn't exceed the console height</param> | ||
/// <param name="foregroundColor">A foreground color that will be changed to.</param> | ||
/// <param name="backgroundColor">A background color that will be changed to.</param> | ||
/// <param name="args">Arguments to format the text</param> | ||
public static void WriteWrapped(string text, Color foregroundColor, Color backgroundColor, bool force = false, params object?[]? args) | ||
{ | ||
lock (TextWriterRaw.WriteLock) | ||
{ | ||
try | ||
{ | ||
// Use the text viewer to avoid code repetition | ||
text = text.FormatString(args); | ||
var lines = ConsoleMisc.GetWrappedSentencesByWords(text, ConsoleWrapper.WindowWidth).ToList(); | ||
if (force || lines.Count >= ConsoleWrapper.WindowHeight) | ||
{ | ||
TextViewInteractive.OpenInteractive(lines, new() | ||
{ | ||
PaneSelectedItemBackColor = foregroundColor, | ||
BackgroundColor = backgroundColor, | ||
}, true); | ||
} | ||
else | ||
TextWriterColor.WriteColorBack(text, foregroundColor, backgroundColor); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine(ex.StackTrace); | ||
Debug.WriteLine($"There is a serious error when printing text. {ex.Message}"); | ||
} | ||
} | ||
} | ||
} | ||
} |