Skip to content

Commit

Permalink
Isolate Style for options controls#
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Cerqueira committed Aug 7, 2023
1 parent 58bcc56 commit 2d265d3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Src/Controls/BaseOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ internal BaseOptions(StyleSchema styleSchema, ConfigControls config, IConsoleCon
{
_console = console;
Config = config;
OptStyleSchema = StyleSchema.Clone(styleSchema);
foreach (var item in config._globalSymbols.Keys)
{
_optSymbols.Add(item, config._globalSymbols[item]);
Expand All @@ -34,14 +35,14 @@ internal BaseOptions(StyleSchema styleSchema, ConfigControls config, IConsoleCon
OptEnabledAbortKey = config.EnabledAbortKey;
}

internal StyleSchema OptStyleSchema { get; }
internal ConfigControls Config { get; }
internal bool OptShowCursor { get; } = false;
internal string OptPrompt { get; set; } = string.Empty;
internal string OptDescription { get; set; } = string.Empty;
internal bool OptShowTooltip { get; set; }

internal Dictionary<StageControl, Action<object, object?>> OptUserActions { get; private set; } = new();
internal StyleSchema OptStyleSchema { get; private set; } = new();
internal string OptToolTip { get; private set; } = string.Empty;
internal bool OptHideAfterFinish { get; private set; }
internal bool OptHideOnAbort { get; private set; }
Expand Down
59 changes: 59 additions & 0 deletions Src/Controls/StyleSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ internal StyleSchema()
_Styles = Init();
}

private StyleSchema(Dictionary<StyleControls, Style> newtyles)
{
_Styles = newtyles;
}

/// <summary>
/// Apply style current instance of control
/// </summary>
Expand Down Expand Up @@ -102,5 +107,59 @@ internal void UpdateBackgoundColor(Color backgoundcolor)
_Styles[item] = stl;
}
}

internal static StyleSchema Clone(StyleSchema source)
{
var auxdic = new Dictionary<StyleControls, Style>();
var aux = Enum.GetValues(typeof(StyleControls)).Cast<StyleControls>();
foreach (var item in aux)
{
switch (item)
{
case StyleControls.Prompt:
auxdic.Add(item, source.Prompt());
break;
case StyleControls.Answer:
auxdic.Add(item, source.Answer());
break;
case StyleControls.Description:
auxdic.Add(item, source.Description());
break;
case StyleControls.Sugestion:
auxdic.Add(item, source.Sugestion());
break;
case StyleControls.Selected:
auxdic.Add(item, source.Selected());
break;
case StyleControls.UnSelected:
auxdic.Add(item, source.UnSelected());
break;
case StyleControls.Disabled:
auxdic.Add(item, source.Disabled());
break;
case StyleControls.Error:
auxdic.Add(item, source.Error());
break;
case StyleControls.Pagination:
auxdic.Add(item, source.Pagination());
break;
case StyleControls.TaggedInfo:
auxdic.Add(item, source.TaggedInfo());
break;
case StyleControls.Tooltips:
auxdic.Add(item, source.Tooltips());
break;
case StyleControls.Slider:
auxdic.Add(item, source.Slider());
break;
case StyleControls.Chart:
auxdic.Add(item, source.Chart());
break;
default:
throw new PromptPlusException($"{item} Not Implemented");
}
}
return new StyleSchema(auxdic);
}
}
}

0 comments on commit 2d265d3

Please sign in to comment.