Code Monkey home page Code Monkey logo

Comments (3)

cronvel avatar cronvel commented on August 20, 2024

@samizdatco That's right, it doesn't support transparency directly.
The purpose of TextBuffer is to manage the text like in a text editor.
It's way more handy than using the ScreenBuffer's low level .put() method.
Moreover, the TextBuffer has a virtually infinite size by default, a thing that is not possible with the more concrete ScreenBuffer.
But things like transparency and composition are ScreenBuffer's job.

In fact, the TextBuffer content is just copied as it is (geometry aware) to the ScreenBuffer.
So the transparency flags are written into the ScreenBuffer instead of being applied.

In your example, if you want to achieve what you want, you need one extra ScreenBuffer.
In fact there should always be a ScreenBuffer backer for each TextBuffer, but you can eventully mutualize them if they do not overlap.
In your example the ScreenBuffer used as the backer has overlapping informations (the one below the TextBuffer).

from terminal-kit.

cronvel avatar cronvel commented on August 20, 2024

@samizdatco This is your modified example:

function useTextBuffer(){
  // place a textbuffer in the middle of the destination 
  // screenbuffer and set its empty cells to be 
  // transparent for bg and char
  foreground = termkit.ScreenBuffer.create({
    dst:background,
    x:10,
    y:8,
    width:20,
    height:3
  })
  
  textbuffer = termkit.TextBuffer.create({
    dst:foreground,
    x:0,
    y:0,
    width:20,
    height:3
  })
  textbuffer.setEmptyCellAttr({
      bgTransparency:true, 
      charTransparency:true
  })

  // the message text should be visible, but the surrounding
  // rows and cols of the TextBuffer should(?) be transparent
  textbuffer.moveTo(2,1)
  textbuffer.insert('hello textbuffer', { bgColor: 'blue' } )
  
  textbuffer.draw()
}

function useScreenBuffer(){
  // place a child screenbuffer in the middle of the
  // parent screenbuffer and draw a similar message
  foreground = termkit.ScreenBuffer.create({
    dst:background,
    x:10,
    y:8,
    width:20,
    height:3
  })

  foreground.put({x:1, y:1}, 'hello screenbuffer')
}

var termkit = require( 'terminal-kit' ),
    term = termkit.terminal,
    textbuffer, foreground, background;

// set up the base ScreenBuffer and add one of our two
// child buffers to it then draw everything to the term
background = termkit.ScreenBuffer.create({
  dst:term,
  x:1, 
  y:1,
  width:40,
  height:20,
  noFill:true
})
background.fill({
  char:'ยท', 
  attr:{color:'white', bgColor:'brightBlue'}
})

useTextBuffer() // or useScreenBuffer()

term.clear()
foreground.draw({blending:true})
background.draw()

Note how there are one more buffer in the .useTextBuffer() method.
Also note that you should give the attr when inserting (.insert()) or it will default to the emptyCellAttr.

from terminal-kit.

samizdatco avatar samizdatco commented on August 20, 2024

Thanks for explaining. That clears things up considerably.

from terminal-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.