diff --git a/Sharprompt/Forms/InputForm.cs b/Sharprompt/Forms/InputForm.cs index 7798362..2c6772b 100644 --- a/Sharprompt/Forms/InputForm.cs +++ b/Sharprompt/Forms/InputForm.cs @@ -14,21 +14,23 @@ public InputForm(InputOptions options) _options = options; - _defaultValue = Optional.Create(options.DefaultValue); + var defaultText = options.DefaultValue?.ToString(); + + if (defaultText is not null) + { + foreach (var c in defaultText) + { + InputBuffer.Insert(c); + } + } } private readonly InputOptions _options; - private readonly Optional _defaultValue; protected override void InputTemplate(OffscreenBuffer offscreenBuffer) { offscreenBuffer.WritePrompt(_options.Message); - if (_defaultValue.HasValue) - { - offscreenBuffer.WriteHint($"({_defaultValue.Value}) "); - } - if (InputBuffer.Length == 0 && !string.IsNullOrEmpty(_options.Placeholder)) { offscreenBuffer.PushCursor(); @@ -56,7 +58,7 @@ protected override bool HandleEnter([NotNullWhen(true)] out T? result) { if (string.IsNullOrEmpty(input)) { - if (!TypeHelper.IsNullable && !_defaultValue.HasValue) + if (!TypeHelper.IsNullable) { SetError(Resource.Validation_Required); @@ -65,7 +67,7 @@ protected override bool HandleEnter([NotNullWhen(true)] out T? result) return false; } - result = _defaultValue; + result = default; } else {