removed bksp from stdin (#306)

* removed bksp from stdin

---------

Co-authored-by: Maas Lalani <maas@lalani.dev>
This commit is contained in:
Mikael Fangel 2023-03-13 21:35:29 +01:00 committed by GitHub
parent ccc5d9cfea
commit ec2b8d0fee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package pager
import (
"fmt"
"regexp"
"github.com/alecthomas/kong"
"github.com/charmbracelet/bubbles/viewport"
@ -22,7 +23,9 @@ func (o Options) Run() error {
return fmt.Errorf("unable to read stdin")
}
if stdin != "" {
o.Content = stdin
// Sanitize the input from stdin by removing backspace sequences.
backspace := regexp.MustCompile(".\x08")
o.Content = backspace.ReplaceAllString(stdin, "")
} else {
return fmt.Errorf("provide some content to display")
}