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

View file

@ -2,6 +2,7 @@ package pager
import ( import (
"fmt" "fmt"
"regexp"
"github.com/alecthomas/kong" "github.com/alecthomas/kong"
"github.com/charmbracelet/bubbles/viewport" "github.com/charmbracelet/bubbles/viewport"
@ -22,7 +23,9 @@ func (o Options) Run() error {
return fmt.Errorf("unable to read stdin") return fmt.Errorf("unable to read stdin")
} }
if 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 { } else {
return fmt.Errorf("provide some content to display") return fmt.Errorf("provide some content to display")
} }