project-nexus
Version:
A hub for all your programming projects
85 lines (61 loc) • 2.09 kB
text/coffeescript
Term = Terminal
class extends React.Component
# : persistent terminal sessions
render: ->
E ".terminal-container"
componentDidMount: ->
if .process
componentDidUpdate: (prev_props)->
if .id isnt prev_props.id
?.destroy()
if .process and .process isnt prev_props.process
init: ->
?.destroy()
proc = .process
term = = new Term
cols: 8
rows: 2
screenKeys: on
convertEol: yes
term.focus = -> # prevent the terminal from recieving focus
container = React.findDOMNode(@)
term.open container
= =>
setTimeout , 50
window.addEventListener "resize",
container.addEventListener "transitionend", , no
# : use https://github.com/chjj/pty.js so more programs will output in color
proc.stdout.on 'data', (data)->
term.write data
proc.stderr.on 'data', (data)->
term.write data
resize: ->
unless
console.log "Terminal::resize, no @term"
return
container = React.findDOMNode(@)
tester_terminal = document.createElement "div"
tester_terminal.className = "terminal"
container.appendChild tester_terminal
tester_div = document.createElement "div"
tester_div.className = "terminal"
tester_terminal.appendChild tester_div
tester = document.createElement "span"
tester.className = "terminal"
tester.style.display = "inline-block"
tester.style.width = "auto"
tester.innerText = "#"
tester_div.appendChild tester
w = container.clientWidth // tester.clientWidth
h = container.clientHeight // tester.clientHeight
console.log "Terminal::resize, #{w}x#{h}"
.resize w, h
container.removeChild tester_terminal
tester_terminal = null
tester = null
componentWillUnmount: ->
window.removeEventListener "resize",
console.log "Terminal: destroying @term"
?.destroy()
= null