Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Replace & improve terminal emulator #409

Merged
merged 30 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
937767a
Remove learn-term.js, use xterm.js and rebuild terminal view
notnotdrew Feb 16, 2017
1c47a21
Merge remote-tracking branch 'origin/master' into terminal
notnotdrew Feb 17, 2017
122b524
Reimplement copy/paste in terminal
notnotdrew Feb 17, 2017
1c4b3bd
Remove openLab from terminal view
notnotdrew Feb 17, 2017
f3060d2
Add terminal focus toggle through keymap
notnotdrew Feb 17, 2017
9c76414
Add clear terminal item to contextmenu
notnotdrew Feb 23, 2017
8f7affb
Handle keymaps for terminal font resizing
notnotdrew Mar 24, 2017
476601c
Catch and parse ctrl characters on win and linux
notnotdrew Mar 27, 2017
0f298e4
Remove learn-term.js and add xterm
notnotdrew Mar 27, 2017
b90bb73
Add fully configurable color scheme
notnotdrew Mar 27, 2017
d6f1f3b
Add inline CSS when writing a new stylesheet fails
notnotdrew Mar 27, 2017
eafaea7
Convert legacy config keys to new color config scheme
notnotdrew Mar 27, 2017
b8bcbca
Add custom color configuration by JSON scheme
notnotdrew Mar 28, 2017
7bca3b8
Improve readability of color configuration
notnotdrew Mar 28, 2017
db23667
Export event-bus after running initialization
notnotdrew Mar 28, 2017
7132081
Introduce working popout-terminal alternative
notnotdrew Mar 28, 2017
384f2e6
Remove legacy popout terminal
notnotdrew Mar 28, 2017
06d37a2
Rename popout-terminal to popout-emulator
notnotdrew Mar 28, 2017
fd73df2
Move popout-emulator script to seperate file
notnotdrew Mar 28, 2017
6eddb86
Include custom terminal colors in popout emulator
notnotdrew Mar 29, 2017
2daacb6
Rewrite colors module using babel as compiler
notnotdrew Mar 29, 2017
af34b25
Use babel to compile the terminal view
notnotdrew Mar 29, 2017
a69c7c0
Fit emulator when popout is resized
notnotdrew Mar 29, 2017
585ac19
Handle keyboard shortcuts in popout emulator
notnotdrew Mar 29, 2017
ef600db
Add custom keydown handler for shortcuts in emulator
notnotdrew Mar 29, 2017
0705321
Restore font & emulator sizing on launch
notnotdrew Mar 29, 2017
c2a1e59
Properly fit emulator on restore & update resize handle styling
notnotdrew Mar 29, 2017
9557b5a
Improve keymaps for win32 and linux
notnotdrew Mar 30, 2017
9aa5b6c
Update color defaults
notnotdrew Apr 25, 2017
bc0aac0
Merge branch 'master' of https://github.com/learn-co/learn-ide into t…
notnotdrew May 5, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions keymaps/learn-ide.cson
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
'.platform-darwin':
'cmd-i': 'learn-ide:toggle-terminal'
'cmd-I': 'learn-ide:toggle-terminal'
'cmd-;': 'learn-ide:toggle-focus'

'.platform-darwin .learn-terminal':
'cmd-c': 'learn-ide:copy'
'cmd-v': 'learn-ide:paste'
'.platform-win32, .platform-linux':
'ctrl-I': 'learn-ide:toggle-terminal'
'ctrl-;': 'learn-ide:toggle-focus'

'.platform-darwin .terminal':
'cmd-=': 'learn-ide:increase-font-size'
'cmd--': 'learn-ide:decrease-font-size'
'cmd-0': 'learn-ide:reset-font-size'

'.platform-win32 .learn-terminal':
# TODO: make these work & remove listeners in TerminalView
# 'ctrl-shift-C': 'learn-ide:copy'
# 'ctrl-shift-V': 'learn-ide:paste'
'.platform-win32 .terminal':
'ctrl-+': 'learn-ide:increase-font-size'
'ctrl-_': 'learn-ide:decrease-font-size'
'ctrl-0': 'learn-ide:reset-font-size'
22 changes: 15 additions & 7 deletions lib/learn-ide.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
localStorage = require './local-storage'
{CompositeDisposable} = require 'atom'
Terminal = require './terminal'
TerminalView = require './views/terminal'
TerminalView = require './terminal-view'
StatusView = require './views/status'
{BrowserWindow} = require 'remote'
{EventEmitter} = require 'events'
Expand Down Expand Up @@ -61,8 +61,7 @@ module.exports =
path: config.path
token: @token.get()

@termView = new TerminalView(@term, null, @isTerminalWindow)
@termView.toggle()
@termView = new TerminalView(@term)

activateStatusView: (state) ->
@statusView = new StatusView state, @term, {@isTerminalWindow}
Expand All @@ -79,7 +78,7 @@ module.exports =

# listen for learn:open event from other render processes (url handler)
bus.on 'learn:open', (lab) =>
@termView.openLab(lab.slug)
@learnOpen(lab.slug)
atom.getCurrentWindow().focus()

# tidy up when the window closes
Expand All @@ -90,16 +89,21 @@ module.exports =

activateSubscriptions: ->
@subscriptions.add atom.commands.add 'atom-workspace',
'learn-ide:open': (e) => @termView.openLab(e.detail.path)
'learn-ide:open': (e) => @learnOpen(e.detail.path)
'learn-ide:toggle-terminal': () => @termView.toggle()
'learn-ide:toggle-focus': => @termView.toggleFocus()
'learn-ide:focus': => @termView.fullFocus()
'learn-ide:focus': => @termView.focusEmulator()
'learn-ide:toggle:debugger': => @term.toggleDebugger()
'learn-ide:reset-connection': => @term.reset()
'learn-ide:view-version': => @viewVersion()
'learn-ide:update-check': -> updater.checkForUpdate()
'learn-ide:about': => @about()

@subscriptions.add atom.commands.add '.terminal',
'core:copy': => @termView.copyText()
'core:paste': => @termView.pasteText()
'learn-ide:clear-terminal': => @term.send(' ')

atom.config.onDidChange "#{name}.terminalFontColor", ({newValue}) =>
@termView.updateFontColor(newValue)

Expand All @@ -112,7 +116,7 @@ module.exports =
openPath = localStorage.get('learnOpenLabOnActivation')
if openPath
localStorage.delete('learnOpenLabOnActivation')
@termView.openLab(openPath)
@learnOpen(openPath)


activateNotifier: ->
Expand Down Expand Up @@ -187,6 +191,10 @@ module.exports =
priority = (rightMostTile?.priority || 0) - 1
statusBar.addRightTile({item: @statusView, priority})

learnOpen: (labSlug) ->
if labSlug?
@term.send("learn open #{labSlug.toString()}\r")

about: ->
shell.openExternal(ABOUT_URL)

Expand Down
80 changes: 80 additions & 0 deletions lib/terminal-view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{$, View} = require 'atom-space-pen-views'
{clipboard} = require 'electron'
TerminalEmulator = require 'xterm'
TerminalEmulator.loadAddon 'fit'

module.exports =
class TerminalView extends View
@content: ->
@div class: 'terminal-resizer tool-panel', =>
@div class: 'terminal-resize-handle', outlet: 'resizeHandle'
@div class: 'emulator-container', outlet: 'emulatorContainer'

initialize: (@terminal) ->
@emulator = new TerminalEmulator({cursorBlink: true})
@subscribe()
@attach()

subscribe: ->
@emulator.on 'data', (data) =>
@terminal.send(data)

@terminal.on 'message', (msg) =>
@emulator.write(msg)

@on 'mousedown', '.terminal-resize-handle', (e) =>
@resizeStarted(e)

attach: ->
atom.workspace.addBottomPanel({item: this})
@emulator.open(@emulatorContainer[0])

copyText: ->
selection = document.getSelection()
rawText = selection.toString()
preparedText = rawText.replace(/\u00A0/g, ' ').replace(/\s+(\n)?$/gm, '$1')

clipboard.writeText(preparedText)

pasteText: ->
rawText = clipboard.readText()
preparedText = rawText.replace(/\n/g, '\r')

@terminal.send(preparedText)

toggleFocus: ->
hasFocus = document.activeElement is @emulator.textarea

if hasFocus then @transferFocus() else @focusEmulator()

transferFocus: ->
atom.workspace.getActivePane().activate()

focusEmulator: ->
@emulator.focus()

resizeStarted: =>
$(document).on('mousemove', @resizeTerminal)
$(document).on('mouseup', @resizeStopped)

resizeStopped: =>
$(document).off('mousemove', @resizeTerminal)
$(document).off('mouseup', @resizeStopped)

resizeTerminal: ({pageY, which}) =>
return @resizeStopped() unless which is 1

height = @outerHeight() + @offset().top - pageY

return if height < 100

# resize container and fit emulator inside it
@emulatorContainer.height(height - @resizeHandle.height())
@emulator.fit()

# then get emulator height and fit containers around it
rowHeight = parseInt(@emulator.rowContainer.style.lineHeight)
newHeight = rowHeight * @emulator.rows
@emulatorContainer.height(newHeight)
@height(newHeight + @resizeHandle.height())

4 changes: 2 additions & 2 deletions lib/terminal.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
utf8 = require 'utf8'
{EventEmitter} = require 'events'
atomHelper = require './atom-helper'
path = require 'path'
Expand Down Expand Up @@ -32,7 +31,8 @@ module.exports = class Terminal extends EventEmitter
resolve()

@socket.on 'message', (message) =>
@emit 'message', utf8.decode(atob(message))
decoded = new Buffer(message, 'base64').toString()
@emit 'message', decoded

@socket.on 'close', =>
@emit 'close'
Expand Down
4 changes: 2 additions & 2 deletions lib/updater.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
fs = require 'fs'
path = require 'path'
{shell} = require 'electron'
semver = require 'semver'
{learnCo} = require './config'
fetch = require './fetch'
Expand Down Expand Up @@ -172,6 +171,8 @@ module.exports =
false

_updateFailed: (detail) ->
{shell, clipboard} = require 'electron'

description = 'The installation seems to have been interrupted.'
buttons = [
{
Expand All @@ -191,7 +192,6 @@ module.exports =
buttons.push
text: 'Copy this log'
onDidClick: ->
{clipboard} = require 'electron'
clipboard.writeText(detail)

@updateNotification =
Expand Down
135 changes: 0 additions & 135 deletions lib/views/terminal-wrapper.coffee

This file was deleted.

Loading