diff --git a/Terminal.Gui/Drawing/Cell.cs b/Terminal.Gui/Drawing/Cell.cs
index 55da051845..16af046a7f 100644
--- a/Terminal.Gui/Drawing/Cell.cs
+++ b/Terminal.Gui/Drawing/Cell.cs
@@ -4,19 +4,18 @@
/// Represents a single row/column in a Terminal.Gui rendering surface (e.g. and
/// ).
///
-public record struct Cell ()
+public record struct Cell (Attribute? Attribute = null, bool IsDirty = false, Rune Rune = default)
{
-
/// The attributes to use when drawing the Glyph.
- public Attribute? Attribute { get; set; } = null;
+ public Attribute? Attribute { get; set; } = Attribute;
///
/// Gets or sets a value indicating whether this has been modified since the
/// last time it was drawn.
///
- public bool IsDirty { get; set; } = false;
+ public bool IsDirty { get; set; } = IsDirty;
- private Rune _rune = default;
+ private Rune _rune = Rune;
/// The character to display. If is , then is ignored.
public Rune Rune
@@ -29,6 +28,8 @@ public Rune Rune
}
}
+ private List _combiningMarks;
+
///
/// The combining marks for that when combined makes this Cell a combining sequence. If
/// empty, then is ignored.
@@ -37,8 +38,153 @@ public Rune Rune
/// Only valid in the rare case where is a combining sequence that could not be normalized to a
/// single Rune.
///
- internal List CombiningMarks { get; } = new ();
+ internal List CombiningMarks
+ {
+ get => _combiningMarks ?? [];
+ private set => _combiningMarks = value ?? [];
+ }
///
public override string ToString () { return $"[{Rune}, {Attribute}]"; }
+
+ /// Converts the string into a .
+ /// The string to convert.
+ /// The to use.
+ ///
+ public static List ToCellList (string str, Attribute? attribute = null)
+ {
+ List cells = new ();
+
+ foreach (Rune rune in str.EnumerateRunes ())
+ {
+ cells.Add (new () { Rune = rune, Attribute = attribute });
+ }
+
+ return cells;
+ }
+
+ ///
+ /// Splits a string into a List that will contain a for each line.
+ ///
+ /// The string content.
+ /// The color scheme.
+ /// A for each line.
+ public static List> StringToLinesOfCells (string content, Attribute? attribute = null)
+ {
+ List cells = content.EnumerateRunes ()
+ .Select (x => new Cell { Rune = x, Attribute = attribute })
+ .ToList ();
+
+ return SplitNewLines (cells);
+ }
+
+ /// Converts a generic collection into a string.
+ /// The enumerable cell to convert.
+ ///
+ public static string ToString (IEnumerable cells)
+ {
+ var str = string.Empty;
+
+ foreach (Cell cell in cells)
+ {
+ str += cell.Rune.ToString ();
+ }
+
+ return str;
+ }
+
+ /// Converts a generic collection into a string.
+ /// The enumerable cell to convert.
+ ///
+ public static string ToString (List> cellsList)
+ {
+ var str = string.Empty;
+
+ for (var i = 0; i < cellsList.Count; i++)
+ {
+ IEnumerable cellList = cellsList [i];
+ str += ToString (cellList);
+
+ if (i + 1 < cellsList.Count)
+ {
+ str += Environment.NewLine;
+ }
+ }
+
+ return str;
+ }
+
+ // Turns the string into cells, this does not split the contents on a newline if it is present.
+
+ internal static List StringToCells (string str, Attribute? attribute = null)
+ {
+ List cells = [];
+
+ foreach (Rune rune in str.ToRunes ())
+ {
+ cells.Add (new () { Rune = rune, Attribute = attribute });
+ }
+
+ return cells;
+ }
+
+ internal static List ToCells (IEnumerable runes, Attribute? attribute = null)
+ {
+ List cells = new ();
+
+ foreach (Rune rune in runes)
+ {
+ cells.Add (new () { Rune = rune, Attribute = attribute });
+ }
+
+ return cells;
+ }
+
+ private static List> SplitNewLines (List cells)
+ {
+ List> lines = [];
+ int start = 0, i = 0;
+ var hasCR = false;
+
+ // ASCII code 13 = Carriage Return.
+ // ASCII code 10 = Line Feed.
+ for (; i < cells.Count; i++)
+ {
+ if (cells [i].Rune.Value == 13)
+ {
+ hasCR = true;
+
+ continue;
+ }
+
+ if (cells [i].Rune.Value == 10)
+ {
+ if (i - start > 0)
+ {
+ lines.Add (cells.GetRange (start, hasCR ? i - 1 - start : i - start));
+ }
+ else
+ {
+ lines.Add (StringToCells (string.Empty));
+ }
+
+ start = i + 1;
+ hasCR = false;
+ }
+ }
+
+ if (i - start >= 0)
+ {
+ lines.Add (cells.GetRange (start, i - start));
+ }
+
+ return lines;
+ }
+
+ ///
+ /// Splits a rune cell list into a List that will contain a for each line.
+ ///
+ /// The cells list.
+ ///
+ public static List> ToCells (List cells) { return SplitNewLines (cells); }
}
diff --git a/Terminal.Gui/Views/RuneCellEventArgs.cs b/Terminal.Gui/Drawing/CellEventArgs.cs
similarity index 57%
rename from Terminal.Gui/Views/RuneCellEventArgs.cs
rename to Terminal.Gui/Drawing/CellEventArgs.cs
index 1283cfe570..f2a8115dc9 100644
--- a/Terminal.Gui/Views/RuneCellEventArgs.cs
+++ b/Terminal.Gui/Drawing/CellEventArgs.cs
@@ -1,27 +1,27 @@
namespace Terminal.Gui;
-/// Args for events that relate to a specific .
-public class RuneCellEventArgs
+/// Args for events that relate to a specific .
+public record struct CellEventArgs
{
- /// Creates a new instance of the class.
+ /// Creates a new instance of the class.
/// The line.
/// The col index.
/// The unwrapped row and col index.
- public RuneCellEventArgs (List line, int col, (int Row, int Col) unwrappedPosition)
+ public CellEventArgs (List line, int col, (int Row, int Col) unwrappedPosition)
{
Line = line;
Col = col;
UnwrappedPosition = unwrappedPosition;
}
- /// The index of the RuneCell in the line.
+ /// The index of the Cell in the line.
public int Col { get; }
- /// The list of runes the RuneCell is part of.
- public List Line { get; }
+ /// The list of runes the Cell is part of.
+ public List Line { get; }
///
- /// The unwrapped row and column index into the text containing the RuneCell. Unwrapped means the text without
+ /// The unwrapped row and column index into the text containing the Cell. Unwrapped means the text without
/// word wrapping or other visual formatting having been applied.
///
public (int Row, int Col) UnwrappedPosition { get; }
diff --git a/Terminal.Gui/Drawing/LineCanvas.cs b/Terminal.Gui/Drawing/LineCanvas.cs
index 9a7365f264..235d657d98 100644
--- a/Terminal.Gui/Drawing/LineCanvas.cs
+++ b/Terminal.Gui/Drawing/LineCanvas.cs
@@ -138,7 +138,7 @@ public void AddLine (
int length,
Orientation orientation,
LineStyle style,
- Attribute? attribute = default
+ Attribute? attribute = null
)
{
_cachedViewport = Rectangle.Empty;
diff --git a/Terminal.Gui/Drawing/StraightLine.cs b/Terminal.Gui/Drawing/StraightLine.cs
index 2f36995df6..fe2ccdc1d0 100644
--- a/Terminal.Gui/Drawing/StraightLine.cs
+++ b/Terminal.Gui/Drawing/StraightLine.cs
@@ -16,7 +16,7 @@ public StraightLine (
int length,
Orientation orientation,
LineStyle style,
- Attribute? attribute = default
+ Attribute? attribute = null
)
{
Start = start;
diff --git a/Terminal.Gui/Resources/Strings.Designer.cs b/Terminal.Gui/Resources/Strings.Designer.cs
index 491473014c..2befd2737b 100644
--- a/Terminal.Gui/Resources/Strings.Designer.cs
+++ b/Terminal.Gui/Resources/Strings.Designer.cs
@@ -1437,6 +1437,15 @@ internal static string btnYes {
}
}
+ ///
+ /// Looks up a localized string similar to Co_lors.
+ ///
+ internal static string ctxColors {
+ get {
+ return ResourceManager.GetString("ctxColors", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to _Copy.
///
diff --git a/Terminal.Gui/Resources/Strings.fr-FR.resx b/Terminal.Gui/Resources/Strings.fr-FR.resx
index 746c454996..c20959da40 100644
--- a/Terminal.Gui/Resources/Strings.fr-FR.resx
+++ b/Terminal.Gui/Resources/Strings.fr-FR.resx
@@ -117,27 +117,27 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ Tout _sélectionner
+
+
+ _Tout supprimer
+
_Copier
Co_uper
-
- _Tout supprimer
-
C_oller
-
- _Rétablir
-
-
- Tout _sélectionner
-
_Annuler
+
+ _Rétablir
+
_Dossier
@@ -168,16 +168,19 @@
Prochai_n...
+
+ Ouvrir
+
Enregistrer
E_nregistrer sous
-
- Ouvrir
-
Sélecteur de Date
+
+ Cou_leurs
+
\ No newline at end of file
diff --git a/Terminal.Gui/Resources/Strings.ja-JP.resx b/Terminal.Gui/Resources/Strings.ja-JP.resx
index 4a825c51c6..fa4bda4210 100644
--- a/Terminal.Gui/Resources/Strings.ja-JP.resx
+++ b/Terminal.Gui/Resources/Strings.ja-JP.resx
@@ -117,27 +117,27 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 全て選択 (_S)
+
+
+ 全て削除 (_D)
+
コピー (_C)
切り取り (_T)
-
- 全て削除 (_D)
-
貼り付け (_P)
-
- やり直し (_R)
-
-
- 全て選択 (_S)
-
元に戻す (_U)
+
+ やり直し (_R)
+
ディレクトリ
@@ -171,44 +171,47 @@
同じ名前のディレクトリはすでに存在しました
-
- “{0}”を削除もよろしいですか?この操作は元に戻りません
-
-
- タイプ
+
+ すでに存在したディレクトリを選択してください
-
- サイズ
+
+ 同じ名前のファイルはすでに存在しました
-
- パスを入力
+
+ すでに存在したファイルを選択してください
ファイル名
-
- 新規ディレクトリ
-
-
- いいえ (_N)
-
-
- はい (_Y)
+
+ すでに存在したファイルまたはディレクトリを選択してください
変更日時
-
- すでに存在したファイルまたはディレクトリを選択してください
+
+ パスを入力
-
- すでに存在したディレクトリを選択してください
+
+ 検索を入力
-
- すでに存在したファイルを選択してください
+
+ サイズ
-
- 名前:
+
+ タイプ
+
+
+ ファイルタイプが間違っでいます
+
+
+ 任意ファイル
+
+
+ “{0}”を削除もよろしいですか?この操作は元に戻りません
+
+
+ 削除失敗
{0} を削除
@@ -216,35 +219,26 @@
新規失敗
-
- 既存
+
+ 新規ディレクトリ
-
- 名前を変更
+
+ いいえ (_N)
変更失敗
-
- 削除失敗
-
-
- 同じ名前のファイルはすでに存在しました
-
-
- 検索を入力
-
-
- ファイルタイプが間違っでいます
+
+ 名前:
-
- 任意ファイル
+
+ 名前を変更
-
- キャンセル (_C)
+
+ はい (_Y)
-
- OK (_O)
+
+ 既存
開く (_O)
@@ -255,6 +249,12 @@
名前を付けて保存 (_S)
+
+ OK (_O)
+
+
+ キャンセル (_C)
+
削除 (_D)
@@ -276,4 +276,7 @@
日付ピッカー
+
+ 絵の具 (_L)
+
\ No newline at end of file
diff --git a/Terminal.Gui/Resources/Strings.pt-PT.resx b/Terminal.Gui/Resources/Strings.pt-PT.resx
index 2cffa6cd7e..28aabf522c 100644
--- a/Terminal.Gui/Resources/Strings.pt-PT.resx
+++ b/Terminal.Gui/Resources/Strings.pt-PT.resx
@@ -117,27 +117,27 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ _Selecionar Tudo
+
+
+ _Apagar Tudo
+
_Copiar
Cor_tar
-
- _Apagar Tudo
-
Co_lar
-
- _Refazer
-
-
- _Selecionar Tudo
-
_Desfazer
+
+ _Refazer
+
Diretório
@@ -168,16 +168,19 @@
S_eguir...
-
- Guardar como
+
+ Abrir
Guardar
-
- Abrir
+
+ Guardar como
Seletor de Data
+
+ Co_res
+
\ No newline at end of file
diff --git a/Terminal.Gui/Resources/Strings.resx b/Terminal.Gui/Resources/Strings.resx
index 8380fb4089..9333d71578 100644
--- a/Terminal.Gui/Resources/Strings.resx
+++ b/Terminal.Gui/Resources/Strings.resx
@@ -1,6 +1,6 @@
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
- text/microsoft-resx
-
-
- 2.0
-
-
- System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
- System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
_Select All
-
+
_Delete All
-
+
_Copy
-
+
Cu_t
-
+
_Paste
-
+
_Undo
-
+
_Redo
-
+
Directory
-
+
File
-
+
Save
-
+
Save as
-
+
Open
-
+
Select folder
-
+
Select Mixed
-
+
_Back
-
+
Fi_nish
-
+
_Next...
-
+
Directory already exists with that name
When trying to save a file with a name already taken by a directory
-
+
Must select an existing directory
-
+
File already exists with that name
-
+
Must select an existing file
When trying to save a directory with a name already used by a file
-
+
Filename
-
+
Must select an existing file or directory
-
+
Modified
-
+
Enter Path
-
+
Enter Search
-
+
Size
-
+
Type
-
+
Wrong file type
When trying to open/save a file that does not match the provided filter (e.g. csv)
-
+
Any Files
Describes an AllowedType that matches anything
-
+
Are you sure you want to delete '{0}'? This operation is permanent
-
+
Delete Failed
-
+
Delete {0}
-
+
New Failed
-
+
New Folder
-
+
_No
-
+
Rename Failed
-
+
Name:
-
+
Rename
-
+
_Yes
-
+
Existing
-
+
O_pen
-
+
_Save
-
+
Save _as
-
+
_OK
-
+
_Cancel
-
+
_Delete
-
+
_Hide {0}
-
+
_New
-
+
_Rename
-
+
_Sort {0} ASC
-
+
_Sort {0} DESC
-
+
Date Picker
-
+
AliceBlue
-
+
AntiqueWhite
-
+
Aquamarine
-
+
Azure
-
+
Beige
-
+
Bisque
-
+
Black
-
+
BlanchedAlmond
-
+
Blue
-
+
BlueViolet
-
+
Brown
-
+
BurlyWood
-
+
CadetBlue
-
+
Chartreuse
-
+
Chocolate
-
+
Coral
-
+
CornflowerBlue
-
+
Cornsilk
-
+
Crimson
-
+
Cyan
-
+
DarkBlue
-
+
DarkCyan
-
+
DarkGoldenRod
-
+
DarkGrey
-
+
DarkGreen
-
+
DarkKhaki
-
+
DarkMagenta
-
+
DarkOliveGreen
-
+
DarkOrange
-
+
DarkOrchid
-
+
DarkRed
-
+
DarkSalmon
-
+
DarkSeaGreen
-
+
DarkSlateBlue
-
+
DarkSlateGrey
-
+
DarkTurquoise
-
+
DarkViolet
-
+
DeepPink
-
+
DeepSkyBlue
-
+
DimGray
-
+
DodgerBlue
-
+
FireBrick
-
+
FloralWhite
-
+
ForestGreen
-
+
Gainsboro
-
+
GhostWhite
-
+
Gold
-
+
GoldenRod
-
+
Gray
-
+
Green
-
+
GreenYellow
-
+
HoneyDew
-
+
HotPink
-
+
IndianRed
-
+
Indigo
-
+
Ivory
-
+
Khaki
-
+
Lavender
-
+
LavenderBlush
-
+
LawnGreen
-
+
LemonChiffon
-
+
LightBlue
-
+
LightCoral
-
+
LightCyan
-
+
LightGoldenRodYellow
-
+
LightGray
-
+
LightGreen
-
+
LightPink
-
+
LightSalmon
-
+
LightSeaGreen
-
+
LightSkyBlue
-
+
LightSlateGrey
-
+
LightSteelBlue
-
+
LightYellow
-
+
Lime
-
+
LimeGreen
-
+
Linen
-
+
Magenta
-
+
Maroon
-
+
MediumAquaMarine
-
+
MediumBlue
-
+
MediumOrchid
-
+
MediumPurple
-
+
MediumSeaGreen
-
+
MediumSlateBlue
-
+
MediumSpringGreen
-
+
MediumTurquoise
-
+
MediumVioletRed
-
+
MidnightBlue
-
+
MintCream
-
+
MistyRose
-
+
Moccasin
-
+
NavajoWhite
-
+
Navy
-
+
OldLace
-
+
Olive
-
+
OliveDrab
-
+
Orange
-
+
OrangeRed
-
+
Orchid
-
+
PaleGoldenRod
-
+
PaleGreen
-
+
PaleTurquoise
-
+
PaleVioletRed
-
+
PapayaWhip
-
+
PeachPuff
-
+
Peru
-
+
Pink
-
+
Plum
-
+
PowderBlue
-
+
Purple
-
+
RebeccaPurple
-
+
Red
-
+
RosyBrown
-
+
RoyalBlue
-
+
SaddleBrown
-
+
Salmon
-
+
SandyBrown
-
+
SeaGreen
-
+
SeaShell
-
+
Sienna
-
+
Silver
-
+
SkyBlue
-
+
SlateBlue
-
+
SlateGray
-
+
Snow
-
+
SpringGreen
-
+
SteelBlue
-
+
Tan
-
+
Teal
-
+
Thistle
-
+
Tomato
-
+
Turquoise
-
+
Violet
-
+
Wheat
-
+
White
-
+
WhiteSmoke
-
+
Yellow
-
+
YellowGreen
-
+
BrightBlue
-
+
BrightCyan
-
+
BrightRed
-
-
+
+
BrightGreen
-
-
+
+
BrightMagenta
-
-
+
+
BrightYellow
-
-
+
+
DarkGray
-
+
+
+ Co_lors
+
\ No newline at end of file
diff --git a/Terminal.Gui/Resources/Strings.zh-Hans.resx b/Terminal.Gui/Resources/Strings.zh-Hans.resx
index 009fdd479f..8ea63e91d6 100644
--- a/Terminal.Gui/Resources/Strings.zh-Hans.resx
+++ b/Terminal.Gui/Resources/Strings.zh-Hans.resx
@@ -153,9 +153,6 @@
打开
-
- 下一步 (_N)...
-
选择文件夹 (_S)
@@ -168,6 +165,9 @@
结束 (_N)
+
+ 下一步 (_N)...
+
已存在相同名称的目录
@@ -240,9 +240,6 @@
已有
-
- 确定 (_O)
-
打开 (_O)
@@ -252,6 +249,9 @@
另存为 (_S)
+
+ 确定 (_O)
+
取消 (_C)
@@ -276,4 +276,7 @@
日期选择器
+
+ 旗帜 (_L)
+
\ No newline at end of file
diff --git a/Terminal.Gui/Text/Autocomplete/AutocompleteContext.cs b/Terminal.Gui/Text/Autocomplete/AutocompleteContext.cs
index 2686c10242..ed55b0d3f4 100644
--- a/Terminal.Gui/Text/Autocomplete/AutocompleteContext.cs
+++ b/Terminal.Gui/Text/Autocomplete/AutocompleteContext.cs
@@ -7,7 +7,7 @@ namespace Terminal.Gui;
public class AutocompleteContext
{
/// Creates a new instance of the class
- public AutocompleteContext (List currentLine, int cursorPosition, bool canceled = false)
+ public AutocompleteContext (List currentLine, int cursorPosition, bool canceled = false)
{
CurrentLine = currentLine;
CursorPosition = cursorPosition;
@@ -18,7 +18,7 @@ public AutocompleteContext (List currentLine, int cursorPosition, bool
public bool Canceled { get; set; }
/// The text on the current line.
- public List CurrentLine { get; set; }
+ public List CurrentLine { get; set; }
/// The position of the input cursor within the .
public int CursorPosition { get; set; }
diff --git a/Terminal.Gui/Views/AutocompleteFilepathContext.cs b/Terminal.Gui/Views/AutocompleteFilepathContext.cs
index f577e554fe..b21724816e 100644
--- a/Terminal.Gui/Views/AutocompleteFilepathContext.cs
+++ b/Terminal.Gui/Views/AutocompleteFilepathContext.cs
@@ -6,7 +6,7 @@ namespace Terminal.Gui;
internal class AutocompleteFilepathContext : AutocompleteContext
{
public AutocompleteFilepathContext (string currentLine, int cursorPosition, FileDialogState state)
- : base (TextModel.ToRuneCellList (currentLine), cursorPosition)
+ : base (Cell.ToCellList (currentLine), cursorPosition)
{
State = state;
}
@@ -30,7 +30,7 @@ public IEnumerable GenerateSuggestions (AutocompleteContext context)
return Enumerable.Empty ();
}
- var path = TextModel.ToString (context.CurrentLine);
+ var path = Cell.ToString (context.CurrentLine);
int last = path.LastIndexOfAny (FileDialog.Separators);
if (string.IsNullOrWhiteSpace (path) || !Path.IsPathRooted (path))
diff --git a/Terminal.Gui/Views/ColorPicker16.cs b/Terminal.Gui/Views/ColorPicker.16.cs
similarity index 100%
rename from Terminal.Gui/Views/ColorPicker16.cs
rename to Terminal.Gui/Views/ColorPicker.16.cs
diff --git a/Terminal.Gui/Views/ColorPicker.Prompt.cs b/Terminal.Gui/Views/ColorPicker.Prompt.cs
new file mode 100644
index 0000000000..3f2372db9a
--- /dev/null
+++ b/Terminal.Gui/Views/ColorPicker.Prompt.cs
@@ -0,0 +1,123 @@
+namespace Terminal.Gui;
+
+public partial class ColorPicker
+{
+ ///
+ /// Open a with two or , based on the
+ /// is false or true, respectively, for
+ /// and colors.
+ ///
+ /// The title to show in the dialog.
+ /// The current attribute used.
+ /// The new attribute.
+ /// if a new color was accepted, otherwise .
+ public static bool Prompt (string title, Attribute? currentAttribute, out Attribute newAttribute)
+ {
+ var accept = false;
+
+ var d = new Dialog
+ {
+ Title = title,
+ Width = Application.Force16Colors ? 37 : Dim.Auto (DimAutoStyle.Auto, Dim.Percent (80), Dim.Percent (90)),
+ Height = 20
+ };
+
+ var btnOk = new Button
+ {
+ X = Pos.Center () - 5,
+ Y = Application.Force16Colors ? 6 : 4,
+ Text = "Ok",
+ Width = Dim.Auto (),
+ IsDefault = true
+ };
+
+ btnOk.Accepting += (s, e) =>
+ {
+ accept = true;
+ e.Cancel = true;
+ Application.RequestStop ();
+ };
+
+ var btnCancel = new Button
+ {
+ X = Pos.Center () + 5,
+ Y = 4,
+ Text = "Cancel",
+ Width = Dim.Auto ()
+ };
+
+ btnCancel.Accepting += (s, e) =>
+ {
+ e.Cancel = true;
+ Application.RequestStop ();
+ };
+
+ d.Add (btnOk);
+ d.Add (btnCancel);
+
+ d.AddButton (btnOk);
+ d.AddButton (btnCancel);
+
+ View cpForeground;
+
+ if (Application.Force16Colors)
+ {
+ cpForeground = new ColorPicker16
+ {
+ SelectedColor = currentAttribute!.Value.Foreground.GetClosestNamedColor16 (),
+ Width = Dim.Fill (),
+ BorderStyle = LineStyle.Single,
+ Title = "Foreground"
+ };
+ }
+ else
+ {
+ cpForeground = new ColorPicker
+ {
+ SelectedColor = currentAttribute!.Value.Foreground,
+ Width = Dim.Fill (),
+ Style = new () { ShowColorName = true, ShowTextFields = true },
+ BorderStyle = LineStyle.Single,
+ Title = "Foreground"
+ };
+ ((ColorPicker)cpForeground).ApplyStyleChanges ();
+ }
+
+ View cpBackground;
+
+ if (Application.Force16Colors)
+ {
+ cpBackground = new ColorPicker16
+ {
+ SelectedColor = currentAttribute!.Value.Background.GetClosestNamedColor16 (),
+ Y = Pos.Bottom (cpForeground) + 1,
+ Width = Dim.Fill (),
+ BorderStyle = LineStyle.Single,
+ Title = "Background"
+ };
+ }
+ else
+ {
+ cpBackground = new ColorPicker
+ {
+ SelectedColor = currentAttribute!.Value.Background,
+ Width = Dim.Fill (),
+ Y = Pos.Bottom (cpForeground) + 1,
+ Style = new () { ShowColorName = true, ShowTextFields = true },
+ BorderStyle = LineStyle.Single,
+ Title = "Background"
+ };
+ ((ColorPicker)cpBackground).ApplyStyleChanges ();
+ }
+
+ d.Add (cpForeground, cpBackground);
+
+ Application.Run (d);
+ d.Dispose ();
+ Color newForeColor = Application.Force16Colors ? ((ColorPicker16)cpForeground).SelectedColor : ((ColorPicker)cpForeground).SelectedColor;
+ Color newBackColor = Application.Force16Colors ? ((ColorPicker16)cpBackground).SelectedColor : ((ColorPicker)cpBackground).SelectedColor;
+ newAttribute = new (newForeColor, newBackColor);
+
+ return accept;
+ }
+}
diff --git a/Terminal.Gui/Views/ColorPickerStyle.cs b/Terminal.Gui/Views/ColorPicker.Style.cs
similarity index 100%
rename from Terminal.Gui/Views/ColorPickerStyle.cs
rename to Terminal.Gui/Views/ColorPicker.Style.cs
diff --git a/Terminal.Gui/Views/ColorPicker.cs b/Terminal.Gui/Views/ColorPicker.cs
index 83a0365d78..a4209ffe42 100644
--- a/Terminal.Gui/Views/ColorPicker.cs
+++ b/Terminal.Gui/Views/ColorPicker.cs
@@ -7,7 +7,7 @@ namespace Terminal.Gui;
///
/// True color picker using HSL
///
-public class ColorPicker : View
+public partial class ColorPicker : View
{
///
/// Creates a new instance of . Use
diff --git a/Terminal.Gui/Views/HistoryTextItemEventArgs.cs b/Terminal.Gui/Views/HistoryTextItemEventArgs.cs
index ca2ad3ad7e..c75f4a5e8b 100644
--- a/Terminal.Gui/Views/HistoryTextItemEventArgs.cs
+++ b/Terminal.Gui/Views/HistoryTextItemEventArgs.cs
@@ -9,11 +9,11 @@ public class HistoryTextItemEventArgs : EventArgs
public Point CursorPosition;
public Point FinalCursorPosition;
public bool IsUndoing;
- public List> Lines;
+ public List> Lines;
public LineStatus LineStatus;
public HistoryTextItemEventArgs RemovedOnAdded;
- public HistoryTextItemEventArgs (List> lines, Point curPos, LineStatus linesStatus)
+ public HistoryTextItemEventArgs (List> lines, Point curPos, LineStatus linesStatus)
{
Lines = lines;
CursorPosition = curPos;
@@ -22,7 +22,7 @@ public HistoryTextItemEventArgs (List> lines, Point curPos, LineS
public HistoryTextItemEventArgs (HistoryTextItemEventArgs historyTextItem)
{
- Lines = new List> (historyTextItem.Lines);
+ Lines = new List> (historyTextItem.Lines);
CursorPosition = new Point (historyTextItem.CursorPosition.X, historyTextItem.CursorPosition.Y);
LineStatus = historyTextItem.LineStatus;
}
diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs
index e5bd503630..7d9785c22c 100644
--- a/Terminal.Gui/Views/TextField.cs
+++ b/Terminal.Gui/Views/TextField.cs
@@ -459,7 +459,7 @@ public virtual int CursorPosition
/// Indicates whatever the text was changed or not. if the text was changed
/// otherwise.
///
- public bool IsDirty => _historyText.IsDirty (Text);
+ public bool IsDirty => _historyText.IsDirty ([Cell.StringToCells (Text)]);
/// If set to true its not allow any changes in the text.
public bool ReadOnly { get; set; }
@@ -541,12 +541,12 @@ public string SelectedText
if (!Secret && !_historyText.IsFromHistory)
{
_historyText.Add (
- new() { TextModel.ToRuneCellList (oldText) },
+ new () { Cell.ToCellList (oldText) },
new (_cursorPosition, 0)
);
_historyText.Add (
- new() { TextModel.ToRuneCells (_text) },
+ new () { Cell.ToCells (_text) },
new (_cursorPosition, 0),
HistoryText.LineStatus.Replaced
);
@@ -589,7 +589,7 @@ public void ClearAllSelection ()
}
/// Allows clearing the items updating the original text.
- public void ClearHistoryChanges () { _historyText.Clear (Text); }
+ public void ClearHistoryChanges () { _historyText.Clear ([Cell.StringToCells (Text)]); }
/// Copy the selected text to the clipboard.
public virtual void Copy ()
@@ -643,7 +643,7 @@ public virtual void DeleteCharLeft (bool usePreTextChangedCursorPos)
}
_historyText.Add (
- new() { TextModel.ToRuneCells (_text) },
+ new () { Cell.ToCells (_text) },
new (_cursorPosition, 0)
);
@@ -697,7 +697,7 @@ public virtual void DeleteCharRight ()
}
_historyText.Add (
- new() { TextModel.ToRuneCells (_text) },
+ new () { Cell.ToCells (_text) },
new (_cursorPosition, 0)
);
@@ -944,7 +944,7 @@ public override void OnDrawContent (Rectangle viewport)
int p = ScrollOffset;
var col = 0;
- int width = Frame.Width + OffSetBackground ();
+ int width = Viewport.Width + OffSetBackground ();
int tcount = _text.Count;
Attribute roc = GetReadOnlyColor ();
@@ -1130,10 +1130,10 @@ public virtual void Paste ()
}
int cols = _text [idx].GetColumns ();
- TextModel.SetCol (ref col, Frame.Width - 1, cols);
+ TextModel.SetCol (ref col, Viewport.Width - 1, cols);
}
- int pos = _cursorPosition - ScrollOffset + Math.Min (Frame.X, 0);
+ int pos = _cursorPosition - ScrollOffset + Math.Min (Viewport.X, 0);
Move (pos, 0);
return new Point (pos, 0);
@@ -1216,16 +1216,16 @@ private void Adjust ()
ScrollOffset = _cursorPosition;
need = true;
}
- else if (Frame.Width > 0
- && (ScrollOffset + _cursorPosition - (Frame.Width + offB) == 0
- || TextModel.DisplaySize (_text, ScrollOffset, _cursorPosition).size >= Frame.Width + offB))
+ else if (Viewport.Width > 0
+ && (ScrollOffset + _cursorPosition - (Viewport.Width + offB) == 0
+ || TextModel.DisplaySize (_text, ScrollOffset, _cursorPosition).size >= Viewport.Width + offB))
{
ScrollOffset = Math.Max (
TextModel.CalculateLeftColumn (
_text,
ScrollOffset,
_cursorPosition,
- Frame.Width + offB
+ Viewport.Width + offB
),
0
);
@@ -1330,7 +1330,7 @@ private List DeleteSelectedText ()
private void GenerateSuggestions ()
{
- List currentLine = TextModel.ToRuneCellList (Text);
+ List currentLine = Cell.ToCellList (Text);
int cursorPosition = Math.Min (CursorPosition, currentLine.Count);
Autocomplete.Context = new (
@@ -1378,7 +1378,7 @@ private void HistoryText_ChangeText (object sender, HistoryText.HistoryTextItemE
return;
}
- Text = TextModel.ToString (obj?.Lines [obj.CursorPosition.Y]);
+ Text = Cell.ToString (obj?.Lines [obj.CursorPosition.Y]);
CursorPosition = obj.CursorPosition.X;
Adjust ();
}
@@ -1386,7 +1386,7 @@ private void HistoryText_ChangeText (object sender, HistoryText.HistoryTextItemE
private void InsertText (Key a, bool usePreTextChangedCursorPos)
{
_historyText.Add (
- new() { TextModel.ToRuneCells (_text) },
+ new () { Cell.ToCells (_text) },
new (_cursorPosition, 0)
);
diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs
index 680a29c205..c34e9220bd 100644
--- a/Terminal.Gui/Views/TextView.cs
+++ b/Terminal.Gui/Views/TextView.cs
@@ -9,44 +9,9 @@
namespace Terminal.Gui;
-///
-/// Represents a single row/column within the . Includes the glyph and the
-/// foreground/background colors.
-///
-[DebuggerDisplay ("{ColorSchemeDebuggerDisplay}")]
-public class RuneCell : IEquatable
-{
- /// The color sets to draw the glyph with.
- [JsonConverter (typeof (ColorSchemeJsonConverter))]
- public ColorScheme? ColorScheme { get; set; }
-
- /// The glyph to draw.
- [JsonConverter (typeof (RuneJsonConverter))]
- public Rune Rune { get; set; }
-
- private string ColorSchemeDebuggerDisplay => ToString ();
-
- /// Indicates whether the current object is equal to another object of the same type.
- /// An object to compare with this object.
- ///
- /// if the current object is equal to the parameter; otherwise,
- /// .
- ///
- public bool Equals (RuneCell? other) { return other is { } && Rune.Equals (other.Rune) && ColorScheme == other.ColorScheme; }
-
- /// Returns a string that represents the current object.
- /// A string that represents the current object.
- public override string ToString ()
- {
- string colorSchemeStr = ColorScheme?.ToString () ?? "null";
-
- return $"U+{Rune.Value:X4} '{Rune.ToString ()}'; {colorSchemeStr}";
- }
-}
-
internal class TextModel
{
- private List> _lines = new ();
+ private List> _lines = new ();
private (Point startPointToFind, Point currentPointToFind, bool found) _toFind;
/// The number of text lines in the model
@@ -56,8 +21,8 @@ internal class TextModel
/// Adds a line to the model at the specified position.
/// Line number where the line will be inserted.
- /// The line of text and color, as a List of RuneCell.
- public void AddLine (int pos, List cells) { _lines.Insert (pos, cells); }
+ /// The line of text and color, as a List of Cell.
+ public void AddLine (int pos, List cells) { _lines.Insert (pos, cells); }
public bool CloseFile ()
{
@@ -72,12 +37,12 @@ public bool CloseFile ()
return true;
}
- public List> GetAllLines () { return _lines; }
+ public List> GetAllLines () { return _lines; }
/// Returns the specified line as a List of Rune
/// The line.
/// Line number to retrieve.
- public List GetLine (int line)
+ public List GetLine (int line)
{
if (_lines.Count > 0)
{
@@ -105,7 +70,7 @@ public int GetMaxVisibleLine (int first, int last, int tabWidth)
for (int i = first; i < last; i++)
{
- List line = GetLine (i);
+ List line = GetLine (i);
int tabSum = line.Sum (c => c.Rune.Value == '\t' ? Math.Max (tabWidth - 1, 0) : 0);
int l = line.Count + tabSum;
@@ -132,17 +97,17 @@ public bool LoadFile (string file)
}
}
- public void LoadListRuneCells (List> cellsList, ColorScheme? colorScheme)
+ public void LoadListCells (List> cellsList, Attribute? attribute)
{
_lines = cellsList;
- SetColorSchemes (colorScheme);
+ SetAttributes (attribute);
OnLinesLoaded ();
}
- public void LoadRuneCells (List cells, ColorScheme? colorScheme)
+ public void LoadCells (List cells, Attribute? attribute)
{
- _lines = ToRuneCells (cells);
- SetColorSchemes (colorScheme);
+ _lines = Cell.ToCells ((List)cells);
+ SetAttributes (attribute);
OnLinesLoaded ();
}
@@ -191,7 +156,7 @@ public void LoadStream (Stream input)
public void LoadString (string content)
{
- _lines = StringToLinesOfRuneCells (content);
+ _lines = Cell.StringToLinesOfCells (content);
OnLinesLoaded ();
}
@@ -211,11 +176,11 @@ public void RemoveLine (int pos)
}
}
- public void ReplaceLine (int pos, List runes)
+ public void ReplaceLine (int pos, List runes)
{
if (_lines.Count > 0 && pos < _lines.Count)
{
- _lines [pos] = new (runes);
+ _lines [pos] = [..runes];
}
else if (_lines.Count == 0 || (_lines.Count > 0 && pos >= _lines.Count))
{
@@ -223,31 +188,7 @@ public void ReplaceLine (int pos, List runes)
}
}
- // Splits a string into a List that contains a List for each line
- public static List> StringToLinesOfRuneCells (string content, ColorScheme? colorScheme = null)
- {
- List cells = content.EnumerateRunes ()
- .Select (x => new RuneCell { Rune = x, ColorScheme = colorScheme })
- .ToList ();
-
- return SplitNewLines (cells);
- }
-
- /// Converts the string into a .
- /// The string to convert.
- /// The to use.
- ///
- public static List ToRuneCellList (string str, ColorScheme? colorScheme = null)
- {
- List cells = new ();
-
- foreach (Rune rune in str.EnumerateRunes ())
- {
- cells.Add (new () { Rune = rune, ColorScheme = colorScheme });
- }
- return cells;
- }
public override string ToString ()
{
@@ -255,7 +196,7 @@ public override string ToString ()
for (var i = 0; i < _lines.Count; i++)
{
- sb.Append (ToString (_lines [i]));
+ sb.Append (Cell.ToString (_lines [i]));
if (i + 1 < _lines.Count)
{
@@ -266,21 +207,6 @@ public override string ToString ()
return sb.ToString ();
}
- /// Converts a generic collection into a string.
- /// The enumerable cell to convert.
- ///
- public static string ToString (IEnumerable cells)
- {
- var str = string.Empty;
-
- foreach (RuneCell cell in cells)
- {
- str += cell.Rune.ToString ();
- }
-
- return str;
- }
-
public (int col, int row)? WordBackward (int fromCol, int fromRow)
{
if (fromRow == 0 && fromCol == 0)
@@ -293,12 +219,12 @@ public static string ToString (IEnumerable cells)
try
{
- RuneCell? cell = RuneAt (col, row);
+ Cell? cell = RuneAt (col, row);
Rune rune;
if (cell is { })
{
- rune = cell.Rune;
+ rune = cell.Value.Rune;
}
else
{
@@ -310,7 +236,7 @@ public static string ToString (IEnumerable cells)
if (col == 0 && row > 0)
{
row--;
- List line = GetLine (row);
+ List line = GetLine (row);
return (line.Count, row);
}
@@ -384,7 +310,7 @@ void ProcMovePrev (ref int nCol, ref int nRow, Rune nRune)
return;
}
- List line = GetLine (nRow);
+ List line = GetLine (nRow);
if (nCol == 0
&& nRow == fromRow
@@ -443,7 +369,7 @@ void ProcMovePrev (ref int nCol, ref int nRow, Rune nRune)
try
{
- Rune rune = RuneAt (col, row).Rune;
+ Rune rune = RuneAt (col, row)!.Value.Rune;
RuneType runeType = GetRuneType (rune);
int lastValidCol = IsSameRuneType (rune, runeType) && (Rune.IsLetterOrDigit (rune) || Rune.IsPunctuation (rune) || Rune.IsSymbol (rune))
@@ -510,7 +436,7 @@ void ProcMoveNext (ref int nCol, ref int nRow, Rune nRune)
return;
}
- List line = GetLine (nRow);
+ List line = GetLine (nRow);
if (nCol == line.Count
&& nRow == fromRow
@@ -550,11 +476,11 @@ void ProcMoveNext (ref int nCol, ref int nRow, Rune nRune)
}
}
- internal static int CalculateLeftColumn (List t, int start, int end, int width, int tabWidth = 0)
+ internal static int CalculateLeftColumn (List t, int start, int end, int width, int tabWidth = 0)
{
List runes = new ();
- foreach (RuneCell cell in t)
+ foreach (Cell cell in t)
{
runes.Add (cell.Rune);
}
@@ -606,7 +532,7 @@ internal static int CalculateLeftColumn (List t, int start, int end, int w
}
internal static (int size, int length) DisplaySize (
- List t,
+ List t,
int start = -1,
int end = -1,
bool checkNextRune = true,
@@ -615,7 +541,7 @@ internal static (int size, int length) DisplaySize (
{
List runes = new ();
- foreach (RuneCell cell in t)
+ foreach (Cell cell in t)
{
runes.Add (cell.Rune);
}
@@ -776,11 +702,11 @@ internal Size GetDisplaySize ()
return foundPos;
}
- internal static int GetColFromX (List t, int start, int x, int tabWidth = 0)
+ internal static int GetColFromX (List t, int start, int x, int tabWidth = 0)
{
List runes = new ();
- foreach (RuneCell cell in t)
+ foreach (Cell cell in t)
{
runes.Add (cell.Rune);
}
@@ -829,7 +755,7 @@ internal static int GetColFromX (List t, int start, int x, int tabWidth =
for (var i = 0; i < _lines.Count; i++)
{
- List x = _lines [i];
+ List x = _lines [i];
string txt = GetText (x);
string matchText = !matchCase ? text.ToUpper () : text;
int col = txt.IndexOf (matchText);
@@ -855,7 +781,7 @@ internal static int GetColFromX (List t, int start, int x, int tabWidth =
found = true;
}
- _lines [i] = ToRuneCellList (ReplaceText (x, textToReplace!, matchText, col));
+ _lines [i] = Cell.ToCellList (ReplaceText (x, textToReplace!, matchText, col));
x = _lines [i];
txt = GetText (x);
pos = new (col, i);
@@ -871,9 +797,9 @@ internal static int GetColFromX (List t, int start, int x, int tabWidth =
}
}
- string GetText (List x)
+ string GetText (List x)
{
- string txt = ToString (x);
+ string txt = Cell.ToString (x);
if (!matchCase)
{
@@ -906,36 +832,10 @@ internal static bool SetCol (ref int col, int width, int cols)
return false;
}
- // Turns the string into cells, this does not split the
- // contents on a newline if it is present.
- internal static List StringToRuneCells (string str, ColorScheme? colorScheme = null)
- {
- List cells = new ();
-
- foreach (Rune rune in str.ToRunes ())
- {
- cells.Add (new () { Rune = rune, ColorScheme = colorScheme });
- }
-
- return cells;
- }
-
- internal static List ToRuneCells (IEnumerable runes, ColorScheme? colorScheme = null)
- {
- List cells = new ();
-
- foreach (Rune rune in runes)
- {
- cells.Add (new () { Rune = rune, ColorScheme = colorScheme });
- }
-
- return cells;
- }
-
private void Append (List line)
{
var str = StringExtensions.ToString (line.ToArray ());
- _lines.Add (StringToRuneCells (str));
+ _lines.Add (Cell.StringToCells (str));
}
private bool ApplyToFind ((Point current, bool found) foundPos)
@@ -971,8 +871,8 @@ Point start
{
for (int i = start.Y; i < linesCount; i++)
{
- List x = _lines [i];
- string txt = ToString (x);
+ List x = _lines [i];
+ string txt = Cell.ToString (x);
if (!matchCase)
{
@@ -1011,8 +911,8 @@ Point start
{
for (int i = linesCount; i >= 0; i--)
{
- List x = _lines [i];
- string txt = ToString (x);
+ List x = _lines [i];
+ string txt = Cell.ToString (x);
if (!matchCase)
{
@@ -1094,7 +994,7 @@ private bool MatchWholeWord (string source, string matchText, int index = 0)
private bool MoveNext (ref int col, ref int row, out Rune rune)
{
- List line = GetLine (row);
+ List line = GetLine (row);
if (col + 1 < line.Count)
{
@@ -1135,7 +1035,7 @@ private bool MoveNext (ref int col, ref int row, out Rune rune)
private bool MovePrev (ref int col, ref int row, out Rune rune)
{
- List line = GetLine (row);
+ List line = GetLine (row);
if (col > 0)
{
@@ -1173,9 +1073,9 @@ private bool MovePrev (ref int col, ref int row, out Rune rune)
private void OnLinesLoaded () { LinesLoaded?.Invoke (this, EventArgs.Empty); }
- private string ReplaceText (List source, string textToReplace, string matchText, int col)
+ private string ReplaceText (List source, string textToReplace, string matchText, int col)
{
- string origTxt = ToString (source);
+ string origTxt = Cell.ToString (source);
(_, int len) = DisplaySize (source, 0, col, false);
(_, int len2) = DisplaySize (source, col, col + matchText.Length, false);
(_, int len3) = DisplaySize (source, col + matchText.Length, origTxt.GetRuneCount (), false);
@@ -1183,72 +1083,31 @@ private string ReplaceText (List source, string textToReplace, string
return origTxt [..len] + textToReplace + origTxt.Substring (len + len2, len3);
}
- private RuneCell RuneAt (int col, int row)
+ private Cell? RuneAt (int col, int row)
{
- List line = GetLine (row);
+ List line = GetLine (row);
if (line.Count > 0)
{
return line [col > line.Count - 1 ? line.Count - 1 : col];
}
- return default (RuneCell)!;
- }
-
- private void SetColorSchemes (ColorScheme? colorScheme)
- {
- foreach (List line in _lines)
- {
- foreach (RuneCell cell in line)
- {
- cell.ColorScheme ??= colorScheme;
- }
- }
+ return null;
}
- private static List> SplitNewLines (List cells)
+ private void SetAttributes (Attribute? attribute)
{
- List> lines = new ();
- int start = 0, i = 0;
- var hasCR = false;
-
- // ASCII code 13 = Carriage Return.
- // ASCII code 10 = Line Feed.
- for (; i < cells.Count; i++)
+ foreach (List line in _lines)
{
- if (cells [i].Rune.Value == 13)
- {
- hasCR = true;
-
- continue;
- }
-
- if (cells [i].Rune.Value == 10)
+ for (var i = 0; i < line.Count; i++)
{
- if (i - start > 0)
- {
- lines.Add (cells.GetRange (start, hasCR ? i - 1 - start : i - start));
- }
- else
- {
- lines.Add (StringToRuneCells (string.Empty));
- }
-
- start = i + 1;
- hasCR = false;
+ Cell cell = line [i];
+ cell.Attribute ??= attribute;
+ line [i] = cell;
}
}
-
- if (i - start >= 0)
- {
- lines.Add (cells.GetRange (start, i - start));
- }
-
- return lines;
}
- private static List> ToRuneCells (List cells) { return SplitNewLines (cells); }
-
private enum RuneType
{
IsSymbol,
@@ -1266,16 +1125,17 @@ public enum LineStatus
Original,
Replaced,
Removed,
- Added
+ Added,
+ Attribute
}
- private readonly List _historyTextItems = new ();
+ private readonly List _historyTextItems = [];
private int _idxHistoryText = -1;
- private string? _originalText;
+ private readonly List> _originalCellsList = [];
public bool HasHistoryChanges => _idxHistoryText > -1;
public bool IsFromHistory { get; private set; }
- public void Add (List> lines, Point curPos, LineStatus lineStatus = LineStatus.Original)
+ public void Add (List> lines, Point curPos, LineStatus lineStatus = LineStatus.Original)
{
if (lineStatus == LineStatus.Original && _historyTextItems.Count > 0 && _historyTextItems.Last ().LineStatus == LineStatus.Original)
{
@@ -1306,15 +1166,51 @@ public void Add (List> lines, Point curPos, LineStatus lineStatus
public event EventHandler? ChangeText;
- public void Clear (string text)
+ public void Clear (List> cellsList)
{
_historyTextItems.Clear ();
_idxHistoryText = -1;
- _originalText = text;
+ _originalCellsList.Clear ();
+ // Save a copy of the original, not the reference
+ foreach (List cells in cellsList)
+ {
+ _originalCellsList.Add ([..cells]);
+ }
+
OnChangeText (null);
}
- public bool IsDirty (string text) { return _originalText != text; }
+ public bool IsDirty (List> cellsList)
+ {
+ if (cellsList.Count != _originalCellsList.Count)
+ {
+ return true;
+ }
+
+ for (var r = 0; r < cellsList.Count; r++)
+ {
+ List cells = cellsList [r];
+ List originalCells = _originalCellsList [r];
+
+ if (cells.Count != originalCells.Count)
+ {
+ return true;
+ }
+
+ for (var c = 0; c < cells.Count; c++)
+ {
+ Cell cell = cells [c];
+ Cell originalCell = originalCells [c];
+
+ if (!cell.Equals (originalCell))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
public void Redo ()
{
@@ -1332,7 +1228,7 @@ public void Redo ()
}
}
- public void ReplaceLast (List> lines, Point curPos, LineStatus lineStatus)
+ public void ReplaceLast (List> lines, Point curPos, LineStatus lineStatus)
{
HistoryTextItemEventArgs? found = _historyTextItems.FindLast (x => x.LineStatus == lineStatus);
@@ -1368,7 +1264,8 @@ private void ProcessChanges (ref HistoryTextItemEventArgs historyTextItem)
if (_idxHistoryText - 1 > -1
&& (_historyTextItems [_idxHistoryText - 1].LineStatus == LineStatus.Added
|| _historyTextItems [_idxHistoryText - 1].LineStatus == LineStatus.Removed
- || (historyTextItem.LineStatus == LineStatus.Replaced && _historyTextItems [_idxHistoryText - 1].LineStatus == LineStatus.Original)))
+ || (historyTextItem.LineStatus == LineStatus.Replaced && _historyTextItems [_idxHistoryText - 1].LineStatus == LineStatus.Original)
+ || (historyTextItem.LineStatus == LineStatus.Attribute && _historyTextItems [_idxHistoryText - 1].LineStatus == LineStatus.Original)))
{
_idxHistoryText--;
@@ -1487,9 +1384,9 @@ public void AddLine (int row, int col)
{
int modelRow = GetModelLineFromWrappedLines (row);
int modelCol = GetModelColFromWrappedLines (row, col);
- List line = GetCurrentLine (modelRow);
+ List line = GetCurrentLine (modelRow);
int restCount = line.Count - modelCol;
- List rest = line.GetRange (modelCol, restCount);
+ List rest = line.GetRange (modelCol, restCount);
line.RemoveRange (modelCol, restCount);
Model.AddLine (modelRow + 1, rest);
_isWrapModelRefreshing = true;
@@ -1573,9 +1470,9 @@ public int GetWrappedLineColWidth (int line, int col, WordWrapManager wrapManage
return modelCol - colWidthOffset;
}
- public bool Insert (int row, int col, RuneCell cell)
+ public bool Insert (int row, int col, Cell cell)
{
- List line = GetCurrentLine (GetModelLineFromWrappedLines (row));
+ List line = GetCurrentLine (GetModelLineFromWrappedLines (row));
line.Insert (GetModelColFromWrappedLines (row, col), cell);
if (line.Count > _frameWidth)
@@ -1589,7 +1486,7 @@ public bool Insert (int row, int col, RuneCell cell)
public bool RemoveAt (int row, int col)
{
int modelRow = GetModelLineFromWrappedLines (row);
- List line = GetCurrentLine (modelRow);
+ List line = GetCurrentLine (modelRow);
int modelCol = GetModelColFromWrappedLines (row, col);
if (modelCol > line.Count)
@@ -1617,7 +1514,7 @@ public bool RemoveLine (int row, int col, out bool lineRemoved, bool forward = t
{
lineRemoved = false;
int modelRow = GetModelLineFromWrappedLines (row);
- List line = GetCurrentLine (modelRow);
+ List line = GetCurrentLine (modelRow);
int modelCol = GetModelColFromWrappedLines (row, col);
if (modelCol == 0 && line.Count == 0)
@@ -1653,7 +1550,7 @@ public bool RemoveLine (int row, int col, out bool lineRemoved, bool forward = t
return false;
}
- List nextLine = Model.GetLine (modelRow + 1);
+ List nextLine = Model.GetLine (modelRow + 1);
line.AddRange (nextLine);
Model.RemoveLine (modelRow + 1);
@@ -1669,7 +1566,7 @@ public bool RemoveLine (int row, int col, out bool lineRemoved, bool forward = t
return false;
}
- List prevLine = Model.GetLine (modelRow - 1);
+ List prevLine = Model.GetLine (modelRow - 1);
prevLine.AddRange (line);
Model.RemoveLine (modelRow);
@@ -1685,7 +1582,7 @@ public bool RemoveLine (int row, int col, out bool lineRemoved, bool forward = t
public bool RemoveRange (int row, int index, int count)
{
int modelRow = GetModelLineFromWrappedLines (row);
- List line = GetCurrentLine (modelRow);
+ List line = GetCurrentLine (modelRow);
int modelCol = GetModelColFromWrappedLines (row, index);
try
@@ -1700,13 +1597,13 @@ public bool RemoveRange (int row, int index, int count)
return true;
}
- public List> ToListRune (List textList)
+ public List> ToListRune (List textList)
{
- List> runesList = new ();
+ List> runesList = new ();
foreach (string text in textList)
{
- runesList.Add (TextModel.ToRuneCellList (text));
+ runesList.Add (Cell.ToCellList (text));
}
return runesList;
@@ -1778,11 +1675,11 @@ public TextModel WrapModel (
for (var i = 0; i < Model.Count; i++)
{
- List line = Model.GetLine (i);
+ List line = Model.GetLine (i);
- List> wrappedLines = ToListRune (
+ List> wrappedLines = ToListRune (
TextFormatter.Format (
- TextModel.ToString (line),
+ Cell.ToString (line),
width,
Alignment.Start,
true,
@@ -1794,7 +1691,7 @@ public TextModel WrapModel (
for (var j = 0; j < wrappedLines.Count; j++)
{
- List wrapLine = wrappedLines [j];
+ List wrapLine = wrappedLines [j];
if (!isRowAndColSet && modelRow == i)
{
@@ -1852,7 +1749,9 @@ public TextModel WrapModel (
for (int k = j; k < wrapLine.Count; k++)
{
- wrapLine [k].ColorScheme = line [k].ColorScheme;
+ Cell cell = wrapLine [k];
+ cell.Attribute = line [k].Attribute;
+ wrapLine [k] = cell;
}
wrappedModel.AddLine (lines, wrapLine);
@@ -1872,7 +1771,7 @@ public TextModel WrapModel (
return wrappedModel;
}
- private List GetCurrentLine (int row) { return Model.GetLine (row); }
+ private List GetCurrentLine (int row) { return Model.GetLine (row); }
private class WrappedLine
{
@@ -1997,7 +1896,7 @@ public TextView ()
CursorVisibility = CursorVisibility.Default;
Used = true;
- // By default, disable hotkeys (in case someome sets Title)
+ // By default, disable hotkeys (in case someone sets Title)
HotKeySpecifier = new ('\xffff');
_model.LinesLoaded += Model_LinesLoaded!;
@@ -2406,6 +2305,16 @@ public TextView ()
}
);
+ AddCommand (
+ Command.Open,
+ () =>
+ {
+ PromptForColors ();
+
+ return true;
+ });
+
+ // Default keybindings for this view
KeyBindings.Remove (Key.Space);
KeyBindings.Remove (Key.Enter);
@@ -2494,6 +2403,8 @@ public TextView ()
KeyBindings.Add (Key.G.WithCtrl, Command.DeleteAll);
KeyBindings.Add (Key.D.WithCtrl.WithShift, Command.DeleteAll);
+ KeyBindings.Add (Key.L.WithCtrl, Command.Open);
+
#if UNIX_KEY_BINDINGS
KeyBindings.Add (Key.C.WithAlt, Command.Copy);
KeyBindings.Add (Key.B.WithAlt, Command.WordLeft);
@@ -2609,7 +2520,7 @@ public Point CursorPosition
get => new (CurrentColumn, CurrentRow);
set
{
- List line = _model.GetLine (Math.Max (Math.Min (value.Y, _model.Count - 1), 0));
+ List line = _model.GetLine (Math.Max (Math.Min (value.Y, _model.Count - 1), 0));
CurrentColumn = value.X < 0 ? 0 :
value.X > line.Count ? line.Count : value.X;
@@ -2629,11 +2540,11 @@ public Point CursorPosition
public bool HasHistoryChanges => _historyText.HasHistoryChanges;
///
- /// If and the current is null will inherit from the
+ /// If and the current is null will inherit from the
/// previous, otherwise if (default) do nothing. If the text is load with
- /// this property is automatically sets to .
+ /// this property is automatically sets to .
///
- public bool InheritsPreviousColorScheme { get; set; }
+ public bool InheritsPreviousAttribute { get; set; }
///
/// Indicates whatever the text was changed or not. if the text was changed
@@ -2641,8 +2552,8 @@ public Point CursorPosition
///
public bool IsDirty
{
- get => _historyText.IsDirty (Text);
- set => _historyText.Clear (Text);
+ get => _historyText.IsDirty (_model.GetAllLines ());
+ set => _historyText.Clear (_model.GetAllLines ());
}
/// Gets or sets the left column.
@@ -2734,6 +2645,22 @@ public bool ReadOnly
/// Length of the selected text.
public int SelectedLength => GetSelectedLength ();
+ ///
+ /// Gets the selected text as
+ ///
+ /// List{List{Cell}}
+ ///
+ ///
+ public List> SelectedCellsList
+ {
+ get
+ {
+ GetRegion (out List> selectedCellsList);
+
+ return selectedCellsList;
+ }
+ }
+
/// The selected text.
public string SelectedText
{
@@ -2757,7 +2684,7 @@ public int SelectionStartColumn
get => _selectionStartColumn;
set
{
- List line = _model.GetLine (_selectionStartRow);
+ List line = _model.GetLine (_selectionStartRow);
_selectionStartColumn = value < 0 ? 0 :
value > line.Count ? line.Count : value;
@@ -2828,7 +2755,7 @@ public override string Text
OnTextChanged ();
SetNeedsDisplay ();
- _historyText.Clear (Text);
+ _historyText.Clear (_model.GetAllLines ());
}
}
@@ -2880,7 +2807,7 @@ public bool WordWrap
/// Allows clearing the items updating the original text.
- public void ClearHistoryChanges () { _historyText?.Clear (Text); }
+ public void ClearHistoryChanges () { _historyText?.Clear (_model.GetAllLines ()); }
/// Closes the contents of the stream into the .
/// true, if stream was closed, false otherwise.
@@ -2902,6 +2829,102 @@ public bool CloseFile ()
///
public event EventHandler? ContentsChanged;
+ internal void ApplyCellsAttribute (Attribute attribute)
+ {
+ if (!ReadOnly && SelectedLength > 0)
+ {
+ int startRow = Math.Min (SelectionStartRow, CurrentRow);
+ int endRow = Math.Max (CurrentRow, SelectionStartRow);
+ int startCol = SelectionStartRow <= CurrentRow ? SelectionStartColumn : CurrentColumn;
+ int endCol = CurrentRow >= SelectionStartRow ? CurrentColumn : SelectionStartColumn;
+ List> selectedCellsOriginal = [];
+ List> selectedCellsChanged = [];
+
+ for (int r = startRow; r <= endRow; r++)
+ {
+ List line = GetLine (r);
+
+ selectedCellsOriginal.Add ([.. line]);
+
+ for (int c = r == startRow ? startCol : 0;
+ c < (r == endRow ? endCol : line.Count);
+ c++)
+ {
+ Cell cell = line [c]; // Copy value to a new variable
+ cell.Attribute = attribute; // Modify the copy
+ line [c] = cell; // Assign the modified copy back
+ }
+
+ selectedCellsChanged.Add ([..GetLine (r)]);
+ }
+
+ GetSelectedRegion ();
+ IsSelecting = false;
+
+ _historyText.Add (
+ [.. selectedCellsOriginal],
+ new (startCol, startRow)
+ );
+
+ _historyText.Add (
+ [.. selectedCellsChanged],
+ new (startCol, startRow),
+ HistoryText.LineStatus.Attribute
+ );
+ }
+ }
+
+ private Attribute? GetSelectedCellAttribute ()
+ {
+ List line;
+
+ if (SelectedLength > 0)
+ {
+ line = GetLine (SelectionStartRow);
+
+ if (line [Math.Min (SelectionStartColumn, line.Count - 1)].Attribute is { } attributeSel)
+ {
+ return new (attributeSel);
+ }
+
+ return new (ColorScheme!.Focus);
+ }
+
+ line = GetCurrentLine ();
+
+ if (line [Math.Min (CurrentColumn, line.Count - 1)].Attribute is { } attribute)
+ {
+ return new (attribute);
+ }
+
+ return new (ColorScheme!.Focus);
+ }
+
+ ///
+ /// Open a dialog to set the foreground and background colors.
+ ///
+ public void PromptForColors ()
+ {
+ if (!ColorPicker.Prompt (
+ "Colors",
+ GetSelectedCellAttribute (),
+ out Attribute newAttribute
+ ))
+ {
+ return;
+ }
+
+ var attribute = new Attribute (
+ newAttribute.Foreground,
+ newAttribute.Background
+ );
+
+ ApplyCellsAttribute (attribute);
+ }
+
+ private string? _copiedText;
+ private List> _copiedCellsList = [];
+
/// Copy the selected text to the clipboard contents.
public void Copy ()
{
@@ -2909,13 +2932,16 @@ public void Copy ()
if (IsSelecting)
{
- SetClipboard (GetRegion ());
+ _copiedText = GetRegion (out _copiedCellsList);
+ SetClipboard (_copiedText);
_copyWithoutSelection = false;
}
else
{
- List currentLine = GetCurrentLine ();
- SetClipboard (TextModel.ToString (currentLine));
+ List currentLine = GetCurrentLine ();
+ _copiedCellsList.Add (currentLine);
+ _copiedText = Cell.ToString (currentLine);
+ SetClipboard (_copiedText);
_copyWithoutSelection = true;
}
@@ -2927,14 +2953,15 @@ public void Copy ()
public void Cut ()
{
SetWrapModel ();
- SetClipboard (GetRegion ());
+ _copiedText = GetRegion (out _copiedCellsList);
+ SetClipboard (_copiedText);
if (!_isReadOnly)
{
ClearRegion ();
_historyText.Add (
- new () { new (GetCurrentLine ()) },
+ [new (GetCurrentLine ())],
CursorPosition,
HistoryText.LineStatus.Replaced
);
@@ -2977,7 +3004,7 @@ public void DeleteCharLeft ()
ClearSelectedRegion ();
- List currentLine = GetCurrentLine ();
+ List currentLine = GetCurrentLine ();
_historyText.Add (
new () { new (currentLine) },
@@ -3021,7 +3048,7 @@ public void DeleteCharRight ()
ClearSelectedRegion ();
- List currentLine = GetCurrentLine ();
+ List currentLine = GetCurrentLine ();
_historyText.Add (
new () { new (currentLine) },
@@ -3050,19 +3077,19 @@ public void DeleteCharRight ()
}
/// Invoked when the normal color is drawn.
- public event EventHandler? DrawNormalColor;
+ public event EventHandler? DrawNormalColor;
/// Invoked when the ready only color is drawn.
- public event EventHandler? DrawReadOnlyColor;
+ public event EventHandler? DrawReadOnlyColor;
/// Invoked when the selection color is drawn.
- public event EventHandler? DrawSelectionColor;
+ public event EventHandler? DrawSelectionColor;
///
/// Invoked when the used color is drawn. The Used Color is used to indicate if the
/// was pressed and enabled.
///
- public event EventHandler? DrawUsedColor;
+ public event EventHandler? DrawUsedColor;
/// Find the next text based on the match case with the option to replace it.
/// The text to find.
@@ -3135,19 +3162,19 @@ public bool FindPreviousText (
/// Gets all lines of characters.
///
- public List> GetAllLines () { return _model.GetAllLines (); }
+ public List> GetAllLines () { return _model.GetAllLines (); }
///
/// Returns the characters on the current line (where the cursor is positioned). Use
/// to determine the position of the cursor within that line
///
///
- public List GetCurrentLine () { return _model.GetLine (CurrentRow); }
+ public List GetCurrentLine () { return _model.GetLine (CurrentRow); }
/// Returns the characters on the .
/// The intended line.
///
- public List GetLine (int line) { return _model.GetLine (line); }
+ public List GetLine (int line) { return _model.GetLine (line); }
///
public override Attribute GetNormalColor ()
@@ -3202,7 +3229,7 @@ public bool Load (string path)
{
SetWrapModel ();
res = _model.LoadFile (path);
- _historyText.Clear (Text);
+ _historyText.Clear (_model.GetAllLines ());
ResetPosition ();
}
finally
@@ -3224,33 +3251,33 @@ public void Load (Stream stream)
{
SetWrapModel ();
_model.LoadStream (stream);
- _historyText.Clear (Text);
+ _historyText.Clear (_model.GetAllLines ());
ResetPosition ();
SetNeedsDisplay ();
UpdateWrapModel ();
}
- /// Loads the contents of the list into the .
+ /// Loads the contents of the list into the .
/// Rune cells list to load the contents from.
- public void Load (List cells)
+ public void Load (List cells)
{
SetWrapModel ();
- _model.LoadRuneCells (cells, ColorScheme);
- _historyText.Clear (Text);
+ _model.LoadCells (cells, ColorScheme?.Focus);
+ _historyText.Clear (_model.GetAllLines ());
ResetPosition ();
SetNeedsDisplay ();
UpdateWrapModel ();
- InheritsPreviousColorScheme = true;
+ InheritsPreviousAttribute = true;
}
- /// Loads the contents of the list of list into the .
+ /// Loads the contents of the list of list into the .
/// List of rune cells list to load the contents from.
- public void Load (List> cellsList)
+ public void Load (List> cellsList)
{
SetWrapModel ();
- InheritsPreviousColorScheme = true;
- _model.LoadListRuneCells (cellsList, ColorScheme);
- _historyText.Clear (Text);
+ InheritsPreviousAttribute = true;
+ _model.LoadListCells (cellsList, ColorScheme?.Focus);
+ _historyText.Clear (_model.GetAllLines ());
ResetPosition ();
SetNeedsDisplay ();
UpdateWrapModel ();
@@ -3346,7 +3373,7 @@ protected internal override bool OnMouseEvent (MouseEvent ev)
}
else if (ev.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition))
{
- ProcessMouseClick (ev, out List line);
+ ProcessMouseClick (ev, out List line);
PositionCursor ();
if (_model.Count > 0 && _shiftSelecting && IsSelecting)
@@ -3445,7 +3472,7 @@ protected internal override bool OnMouseEvent (MouseEvent ev)
StopSelecting ();
}
- ProcessMouseClick (ev, out List line);
+ ProcessMouseClick (ev, out List line);
(int col, int row)? newPos;
if (CurrentColumn == line.Count
@@ -3482,7 +3509,7 @@ protected internal override bool OnMouseEvent (MouseEvent ev)
StopSelecting ();
}
- ProcessMouseClick (ev, out List line);
+ ProcessMouseClick (ev, out List line);
CurrentColumn = 0;
if (!IsSelecting)
@@ -3508,7 +3535,7 @@ protected internal override bool OnMouseEvent (MouseEvent ev)
public void MoveEnd ()
{
CurrentRow = _model.Count - 1;
- List line = GetCurrentLine ();
+ List line = GetCurrentLine ();
CurrentColumn = line.Count;
TrackColumn ();
PositionCursor ();
@@ -3553,7 +3580,7 @@ public override void OnDrawContent (Rectangle viewport)
for (int idxRow = _topRow; idxRow < _model.Count; idxRow++)
{
- List line = _model.GetLine (idxRow);
+ List line = _model.GetLine (idxRow);
int lineRuneCount = line.Count;
var col = 0;
@@ -3601,6 +3628,8 @@ public override void OnDrawContent (Rectangle viewport)
else
{
AddRune (col, row, rune);
+ // Ensures that cols less than 0 to be 1 because it will be converted to a printable rune
+ cols = Math.Max (cols, 1);
}
if (!TextModel.SetCol (ref col, viewport.Right, cols))
@@ -3721,17 +3750,17 @@ public void Paste ()
SetWrapModel ();
string? contents = Clipboard.Contents;
- if (_copyWithoutSelection && contents.FirstOrDefault (x => x == '\n' || x == '\r') == 0)
+ if (_copyWithoutSelection && contents.FirstOrDefault (x => x is '\n' or '\r') == 0)
{
- List runeList = contents is null ? new () : TextModel.ToRuneCellList (contents);
- List currentLine = GetCurrentLine ();
+ List runeList = contents is null ? [] : Cell.ToCellList (contents);
+ List currentLine = GetCurrentLine ();
- _historyText.Add (new () { new (currentLine) }, CursorPosition);
+ _historyText.Add ([new (currentLine)], CursorPosition);
- List> addedLine = new () { new (currentLine), runeList };
+ List> addedLine = [new (currentLine), runeList];
_historyText.Add (
- new (addedLine),
+ [..addedLine],
CursorPosition,
HistoryText.LineStatus.Added
);
@@ -3740,7 +3769,7 @@ public void Paste ()
CurrentRow++;
_historyText.Add (
- new () { new (GetCurrentLine ()) },
+ [new (GetCurrentLine ())],
CursorPosition,
HistoryText.LineStatus.Replaced
);
@@ -3756,12 +3785,12 @@ public void Paste ()
}
_copyWithoutSelection = false;
- InsertAllText (contents);
+ InsertAllText (contents, true);
if (IsSelecting)
{
_historyText.ReplaceLast (
- new () { new (GetCurrentLine ()) },
+ [new (GetCurrentLine ())],
CursorPosition,
HistoryText.LineStatus.Original
);
@@ -3794,7 +3823,7 @@ public void Paste ()
SetNeedsDisplay ();
}
- List line = _model.GetLine (CurrentRow);
+ List line = _model.GetLine (CurrentRow);
var col = 0;
if (line.Count > 0)
@@ -3812,6 +3841,11 @@ public void Paste ()
{
cols += TabWidth + 1;
}
+ else
+ {
+ // Ensures that cols less than 0 to be 1 because it will be converted to a printable rune
+ cols = Math.Max (cols, 1);
+ }
if (!TextModel.SetCol (ref col, Viewport.Width, cols))
{
@@ -3948,16 +3982,16 @@ public void Undo ()
/// The line.
/// The col index.
/// The row index.
- protected virtual void OnDrawNormalColor (List line, int idxCol, int idxRow)
+ protected virtual void OnDrawNormalColor (List line, int idxCol, int idxRow)
{
(int Row, int Col) unwrappedPos = GetUnwrappedPosition (idxRow, idxCol);
- var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos);
+ var ev = new CellEventArgs (line, idxCol, unwrappedPos);
DrawNormalColor?.Invoke (this, ev);
- if (line [idxCol].ColorScheme is { })
+ if (line [idxCol].Attribute is { })
{
- ColorScheme? colorScheme = line [idxCol].ColorScheme;
- Driver.SetAttribute (Enabled ? colorScheme!.Focus : colorScheme!.Disabled);
+ Attribute? attribute = line [idxCol].Attribute;
+ Driver.SetAttribute ((Attribute)attribute!);
}
else
{
@@ -3974,22 +4008,22 @@ protected virtual void OnDrawNormalColor (List line, int idxCol, int i
/// The col index.
/// ///
/// The row index.
- protected virtual void OnDrawReadOnlyColor (List line, int idxCol, int idxRow)
+ protected virtual void OnDrawReadOnlyColor (List line, int idxCol, int idxRow)
{
(int Row, int Col) unwrappedPos = GetUnwrappedPosition (idxRow, idxCol);
- var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos);
+ var ev = new CellEventArgs (line, idxCol, unwrappedPos);
DrawReadOnlyColor?.Invoke (this, ev);
- ColorScheme? colorScheme = line [idxCol].ColorScheme is { } ? line [idxCol].ColorScheme : ColorScheme;
+ Attribute? cellAttribute = line [idxCol].Attribute is { } ? line [idxCol].Attribute : ColorScheme?.Disabled;
Attribute attribute;
- if (colorScheme!.Disabled.Foreground == colorScheme.Focus.Background)
+ if (cellAttribute!.Value.Foreground == cellAttribute.Value.Background)
{
- attribute = new (colorScheme.Focus.Foreground, colorScheme.Focus.Background);
+ attribute = new (cellAttribute.Value.Foreground, cellAttribute.Value.Background);
}
else
{
- attribute = new (colorScheme.Disabled.Foreground, colorScheme.Focus.Background);
+ attribute = new (cellAttribute.Value.Foreground, ColorScheme!.Focus.Background);
}
Driver.SetAttribute (attribute);
@@ -4004,18 +4038,18 @@ protected virtual void OnDrawReadOnlyColor (List line, int idxCol, int
/// The col index.
/// ///
/// The row index.
- protected virtual void OnDrawSelectionColor (List line, int idxCol, int idxRow)
+ protected virtual void OnDrawSelectionColor (List line, int idxCol, int idxRow)
{
(int Row, int Col) unwrappedPos = GetUnwrappedPosition (idxRow, idxCol);
- var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos);
+ var ev = new CellEventArgs (line, idxCol, unwrappedPos);
DrawSelectionColor?.Invoke (this, ev);
- if (line [idxCol].ColorScheme is { })
+ if (line [idxCol].Attribute is { })
{
- ColorScheme? colorScheme = line [idxCol].ColorScheme;
+ Attribute? attribute = line [idxCol].Attribute;
Driver.SetAttribute (
- new (colorScheme!.Focus.Background, colorScheme.Focus.Foreground)
+ new (attribute!.Value.Background, attribute.Value.Foreground)
);
}
else
@@ -4038,20 +4072,20 @@ protected virtual void OnDrawSelectionColor (List line, int idxCol, in
/// The col index.
/// ///
/// The row index.
- protected virtual void OnDrawUsedColor (List line, int idxCol, int idxRow)
+ protected virtual void OnDrawUsedColor (List line, int idxCol, int idxRow)
{
(int Row, int Col) unwrappedPos = GetUnwrappedPosition (idxRow, idxCol);
- var ev = new RuneCellEventArgs (line, idxCol, unwrappedPos);
+ var ev = new CellEventArgs (line, idxCol, unwrappedPos);
DrawUsedColor?.Invoke (this, ev);
- if (line [idxCol].ColorScheme is { })
+ if (line [idxCol].Attribute is { })
{
- ColorScheme? colorScheme = line [idxCol].ColorScheme;
- SetValidUsedColor (colorScheme!);
+ Attribute? attribute = line [idxCol].Attribute;
+ SetValidUsedColor (attribute!);
}
else
{
- SetValidUsedColor (ColorScheme);
+ SetValidUsedColor (ColorScheme?.Focus);
}
}
@@ -4064,7 +4098,7 @@ protected virtual void OnDrawUsedColor (List line, int idxCol, int idx
private void Adjust ()
{
(int width, int height) offB = OffSetBackground ();
- List line = GetCurrentLine ();
+ List line = GetCurrentLine ();
bool need = NeedsDisplay || _wrapNeeded || !Used;
(int size, int length) tSize = TextModel.DisplaySize (line, -1, -1, false, TabWidth);
(int size, int length) dSize = TextModel.DisplaySize (line, _leftColumn, CurrentColumn, true, TabWidth);
@@ -4194,6 +4228,14 @@ private void Adjust ()
null,
null,
(KeyCode)KeyBindings.GetKeyFromCommands (Command.Redo)
+ ),
+ new (
+ Strings.ctxColors,
+ "",
+ () => PromptForColors (),
+ null,
+ null,
+ (KeyCode)KeyBindings.GetKeyFromCommands (Command.Open)
)
}
);
@@ -4226,11 +4268,11 @@ private void ClearRegion ()
var maxrow = (int)(end >> 32);
var startCol = (int)(start & 0xffffffff);
var endCol = (int)(end & 0xffffffff);
- List line = _model.GetLine (startRow);
+ List line = _model.GetLine (startRow);
_historyText.Add (new () { new (line) }, new (startCol, startRow));
- List> removedLines = new ();
+ List> removedLines = new ();
if (startRow == maxrow)
{
@@ -4265,7 +4307,7 @@ private void ClearRegion ()
removedLines.Add (new (line));
line.RemoveRange (startCol, line.Count - startCol);
- List line2 = _model.GetLine (maxrow);
+ List line2 = _model.GetLine (maxrow);
line.AddRange (line2.Skip (endCol));
for (int row = startRow + 1; row <= maxrow; row++)
@@ -4316,7 +4358,7 @@ private bool DeleteTextBackwards ()
if (CurrentColumn > 0)
{
// Delete backwards
- List currentLine = GetCurrentLine ();
+ List currentLine = GetCurrentLine ();
_historyText.Add (new () { new (currentLine) }, CursorPosition);
@@ -4356,11 +4398,11 @@ private bool DeleteTextBackwards ()
}
int prowIdx = CurrentRow - 1;
- List prevRow = _model.GetLine (prowIdx);
+ List prevRow = _model.GetLine (prowIdx);
_historyText.Add (new () { new (prevRow) }, CursorPosition);
- List> removedLines = new () { new (prevRow) };
+ List> removedLines = new () { new (prevRow) };
removedLines.Add (new (GetCurrentLine ()));
@@ -4400,7 +4442,7 @@ private bool DeleteTextForwards ()
{
SetWrapModel ();
- List currentLine = GetCurrentLine ();
+ List | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |