mafintosh / mafintosh/diffy

Render bug on filled-up screen

Open
#6 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
188
Forks
18
PR merge metrics
No merged PRs in 30d

Description

Hi --
First of all-- this package is amazing 👍

I'm experiencing a weird bug. My set up is that I have an array of messages that get rendered on each line and there's a single input at the bottom, kind of like a chat ui. When I hit enter on the line, it's pushed to the messages array. The problem seems to be under these conditions:

a) if the terminal screen has been completely filled up (so some scrolling has happened) and
b) I filter the messages array down drastically

The result is that the input ends up in some weird place, and typing overwrites stuff. It just kinda glitches out.

To reproduce, here is some code:

const Diffy = require('diffy')
const trim = require('diffy/trim')
const Input = require('diffy/input')

const messages = []
const visibleMessages = () => messages.filter((x, i) => i % 2 === 0)

let filter

const diffy = Diffy({ fullscreen: false })
const input = Input({ showCursor: true })

// rerender while i type
input.on('update', () => diffy.render())

// add a line when i hit enter
input.on('enter', (line) => {
  if (line.indexOf('/now') === 0) {
    filter = true
  } else {
    messages.push({
      text: line,
      time: Date.now()
    })
  }
})

// fill up messages with something that would fill a screen
for (let i = 0; i < 200; i++) {
  messages.push({
    text: i.toString(16),
    time: Date.now()
  })
}

diffy.render(() => trim(`
  ${(filter ? visibleMessages() : messages).map(m => `${m.time}  ${m.text}`).join('\n')}
  > ${input.line()}
`))

setInterval(() => diffy.render(), 100)

If you run this, it should fill up the screen with messages, and then you can type /now (enter) to apply the filtering and that's when the bug happens.

(Of course if I'm just misusing the package let me know)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided JavaScript reproduction with diffy, diffy/trim, and diffy/input, then inspect the rendering and input behavior after the screen fills and the messages array is filtered. Done means applying the filter leaves the input in the correct position without overwriting terminal content.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.