diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 5ccf9e1..0000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "yat"] - path = yat - url = https://github.com/Swordifish90/yat - branch = stable diff --git a/cool-old-term.pro b/cool-old-term.pro index 289a9ff..bcc346a 100644 --- a/cool-old-term.pro +++ b/cool-old-term.pro @@ -1,4 +1,4 @@ -QT += widgets quick +QT += widgets quick core-private gui-private qml-private quick quick-private include(yat/yat_declarative/yat_declarative.pro) diff --git a/qml/cool-old-term/HighlightArea.qml b/qml/cool-old-term/HighlightArea.qml index bc40a1c..3a81c9f 100644 --- a/qml/cool-old-term/HighlightArea.qml +++ b/qml/cool-old-term/HighlightArea.qml @@ -1,3 +1,26 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + import QtQuick 2.0 Item { @@ -5,15 +28,19 @@ Item { property real characterWidth: 0 property real characterHeight: 0 - property int screenWidth: width / characterWidth + property int screenWidth: 0 - property point start - property point end + property int startX + property int startY + + property int endX + property int endY property color color: "grey" + y: startY * characterHeight width: parent.width - height: parent.height + height: (endY - startY + 1) * characterHeight opacity: 0.8 @@ -48,27 +75,29 @@ Item { onCharacterHeightChanged: calculateRectangles(); onScreenWidthChanged: calculateRectangles(); - onStartChanged: calculateRectangles(); - onEndChanged: calculateRectangles(); + onStartXChanged: calculateRectangles(); + onStartYChanged: calculateRectangles(); + onEndXChanged: calculateRectangles(); + onEndYChanged: calculateRectangles(); function calculateRectangles() { - highlightArea.y = start.y * characterHeight; - begginning_rectangle.x = start.x * characterWidth; - if (start.y === end.y) { + highlightArea.y = startY * characterHeight; + begginning_rectangle.x = startX * characterWidth; + if (startY === endY) { middle_rectangle.visible = false; end_rectangle.visible = false - begginning_rectangle.width = (end.x - start.x) * characterWidth; + begginning_rectangle.width = (endX - startX) * characterWidth; } else { - begginning_rectangle.width = (screenWidth - start.x) * characterWidth; - if (start.y === end.y - 1) { + begginning_rectangle.width = (screenWidth - startX) * characterWidth; + if (startY === endY - 1) { middle_rectangle.height = 0; middle_rectangle.visible = false; }else { middle_rectangle.visible = true; - middle_rectangle.height = (end.y - start.y - 1) * characterHeight; + middle_rectangle.height = (endY - startY - 1) * characterHeight; } end_rectangle.visible = true; - end_rectangle.width = end.x * characterWidth; + end_rectangle.width = endX * characterWidth; } } diff --git a/qml/cool-old-term/TerminalCursor.qml b/qml/cool-old-term/TerminalCursor.qml new file mode 100644 index 0000000..a37e682 --- /dev/null +++ b/qml/cool-old-term/TerminalCursor.qml @@ -0,0 +1,66 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +import QtQuick 2.0 + +import org.yat 1.0 + +ObjectDestructItem { + id: cursor + + property real fontHeight + property real fontWidth + + height: fontHeight + width: fontWidth + x: objectHandle.x * fontWidth + y: objectHandle.y * fontHeight + z: 1.1 + + visible: objectHandle.visible + + ShaderEffect { + anchors.fill: parent + + property variant source: fragmentSource + + fragmentShader: + "uniform lowp float qt_Opacity;" + + "uniform sampler2D source;" + + "varying highp vec2 qt_TexCoord0;" + + + "void main() {" + + " lowp vec4 color = texture2D(source, qt_TexCoord0 ) * qt_Opacity;" + + " gl_FragColor = vec4(1.0 - color.r, 1.0 - color.g, 1.0 - color.b, color.a);" + + "}" + + ShaderEffectSource { + id: fragmentSource + sourceItem: background + live: true + + sourceRect: Qt.rect(cursor.x,cursor.y,cursor.width,cursor.height); + } + } +} + diff --git a/qml/cool-old-term/TerminalScreen.qml b/qml/cool-old-term/TerminalScreen.qml index b5503ea..ca8c3b6 100644 --- a/qml/cool-old-term/TerminalScreen.qml +++ b/qml/cool-old-term/TerminalScreen.qml @@ -1,4 +1,28 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + import QtQuick 2.0 +import QtQuick.Controls 1.1 import org.yat 1.0 @@ -10,10 +34,35 @@ TerminalScreen { property real fontHeight: fontMetricText.paintedHeight property var lineComponent : Qt.createComponent("TerminalLine.qml") + property var textComponent : Qt.createComponent("TerminalText.qml") + property var cursorComponent : Qt.createComponent("TerminalCursor.qml") font.family: "Pet Me" - font.pointSize: 14 - //font.bold: true + font.pixelSize: 20 + focus: true + + Action { + id: copyAction + shortcut: "Ctrl+Shift+C" + onTriggered: screen.selection.sendToClipboard() + } + Action { + id: paseAction + shortcut: "Ctrl+Shift+V" + onTriggered: screen.selection.pasteFromClipboard() + } + + onActiveFocusChanged: { + if (activeFocus) { + Qt.inputMethod.show(); + } + } + + Keys.onPressed: { + if (event.text === "?") { + terminal.screen.printScreen() + } + } Text { id: fontMetricText @@ -23,10 +72,47 @@ TerminalScreen { textFormat: Text.PlainText } - Rectangle { - id: background - anchors.fill: parent - color: "black" + Flickable { + id: flickable + anchors.top: parent.top + anchors.left: parent.left + contentWidth: width + contentHeight: textContainer.height + interactive: true + flickableDirection: Flickable.VerticalFlick + contentY: ((screen.contentHeight - screen.height) * screenItem.fontHeight) + + Item { + id: textContainer + width: parent.width + height: screen.contentHeight * screenItem.fontHeight + Rectangle { + id: background + anchors.fill: parent + color: terminal.screen.defaultBackgroundColor + } + + HighlightArea { + characterHeight: fontHeight + characterWidth: fontWidth + screenWidth: terminalWindow.width + + startX: screen.selection.startX + startY: screen.selection.startY + + endX: screen.selection.endX + endY: screen.selection.endY + + visible: screen.selection.enable + } + } + + onContentYChanged: { + if (!atYEnd) { + var top_line = Math.floor(Math.max(contentY,0) / screenItem.fontHeight); + screen.ensureVisiblePages(top_line); + } + } } Connections { @@ -38,24 +124,44 @@ TerminalScreen { flashAnimation.start() } - onCursorPositionChanged: { - cursor.x = x * fontWidth; - cursor.y = y * fontHeight; - } - onReset: { resetScreenItems(); } - onLineCreated: { - var lineVariable = lineComponent.createObject(screenItem, + onTextCreated: { + var textSegment = textComponent.createObject(screenItem, { - "objectHandle" : line, - "font": screenItem.font, + "parent" : background, + "objectHandle" : text, + "font" : screenItem.font, "fontWidth" : screenItem.fontWidth, "fontHeight" : screenItem.fontHeight, }) } + + onCursorCreated: { + if (cursorComponent.status != Component.Ready) { + console.log(cursorComponent.errorString()); + return; + } + var cursorVariable = cursorComponent.createObject(screenItem, + { + "parent" : textContainer, + "objectHandle" : cursor, + "fontWidth" : screenItem.fontWidth, + "fontHeight" : screenItem.fontHeight, + }) + } + + onRequestHeightChange: { + terminalWindow.height = newHeight * screenItem.fontHeight; + terminalWindow.contentItem.height = newHeight * screenItem.fontHeight; + } + + onRequestWidthChange: { + terminalWindow.width = newWidth * screenItem.fontWidth; + terminalWindow.contentItem.width = newWidth * screenItem.fontWidth; + } } onFontChanged: { @@ -77,6 +183,7 @@ TerminalScreen { function setTerminalWidth() { if (fontWidth > 0) { var pty_width = Math.floor(width / fontWidth); + flickable.width = pty_width * fontWidth; screen.width = pty_width; } } @@ -84,50 +191,16 @@ TerminalScreen { function setTerminalHeight() { if (fontHeight > 0) { var pty_height = Math.floor(height / fontHeight); + flickable.height = pty_height * fontHeight; screen.height = pty_height; } } - - Item { - id: keyHandler - focus: true - Keys.onPressed: { - terminal.screen.sendKey(event.text, event.key, event.modifiers); - if (event.text === "?") { - terminal.screen.printScreen() - } - } - } - - HighlightArea { - characterHeight: fontHeight - characterWidth: fontWidth - - start: screen.selectionAreaStart - end: screen.selectionAreaEnd - - visible: screen.selectionEnabled - } - - Rectangle { - id: cursor - width: fontWidth - height: fontHeight - x: 0 - y: 0 - color: "white" -// SequentialAnimation on opacity{ -// NumberAnimation{from: 0; to: 1; duration: 500} -// NumberAnimation{from: 1; to: 0; duration: 500} -// loops: Animation.Infinite -// } - } - Rectangle { id: flash + z: 1.2 anchors.fill: parent - color: "white" + color: "grey" opacity: 0 SequentialAnimation { id: flashAnimation @@ -149,39 +222,49 @@ TerminalScreen { MouseArea { id:mousArea - property point drag_start + property int drag_start_x + property int drag_start_y anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.MiddleButton onPressed: { if (mouse.button == Qt.LeftButton) { hoverEnabled = true; - var character = Math.floor((mouse.x / screen.charWidth)); - var line = Math.floor(mouse.y / screen.lineHeight); + var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); + var character = Math.floor((transformed_mouse.x / fontWidth)); + var line = Math.floor(transformed_mouse.y / fontHeight); var start = Qt.point(character,line); - drag_start = start; - screen.selectionAreaStart = start; - screen.selectionAreaEnd = start; + drag_start_x = character; + drag_start_y = line; + screen.selection.startX = character; + screen.selection.startY = line; + screen.selection.endX = character; + screen.selection.endY = line; } } onPositionChanged: { - var character = Math.floor(mouse.x / screen.charWidth); - var line = Math.floor(mouse.y / screen.lineHeight); + var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); + var character = Math.floor(transformed_mouse.x / fontWidth); + var line = Math.floor(transformed_mouse.y / fontHeight); var current_pos = Qt.point(character,line); - if (line < drag_start.y || (line === drag_start.y && character < drag_start.x)) { - screen.selectionAreaStart = current_pos; - screen.selectionAreaEnd = drag_start; + if (line < drag_start_y || (line === drag_start_y && character < drag_start_x)) { + screen.selection.startX = character; + screen.selection.startY = line; + screen.selection.endX = drag_start_x; + screen.selection.endY = drag_start_y; }else { - screen.selectionAreaEnd = current_pos; - screen.selectionAreaStart = drag_start; + screen.selection.startX = drag_start_x; + screen.selection.startY = drag_start_y; + screen.selection.endX = character; + screen.selection.endY = line; } } onReleased: { if (mouse.button == Qt.LeftButton) { hoverEnabled = false; - screen.sendSelectionToSelection(); + screen.selection.sendToSelection(); } } @@ -190,10 +273,12 @@ TerminalScreen { screen.pasteFromSelection(); } } + onDoubleClicked: { if (mouse.button == Qt.LeftButton) { - var character = Math.floor(mouse.x / screen.charWidth); - var line = Math.floor(mouse.y / screen.lineHeight); + var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); + var character = Math.floor(transformed_mouse.x / fontWidth); + var line = Math.floor(transformed_mouse.y / fontHeight); screen.doubleClicked(Qt.point(character,line)); } } diff --git a/qml/cool-old-term/TerminalText.qml b/qml/cool-old-term/TerminalText.qml index e0d0670..704fee2 100644 --- a/qml/cool-old-term/TerminalText.qml +++ b/qml/cool-old-term/TerminalText.qml @@ -29,9 +29,10 @@ ObjectDestructItem { id: textItem property font font property real fontWidth + property real fontHeight - y: 0 - x: 0 + y: objectHandle.line * fontHeight; + x: objectHandle.index * fontWidth; width: textElement.paintedWidth height: textElement.paintedHeight @@ -40,39 +41,41 @@ ObjectDestructItem { Rectangle { anchors.fill: parent - color: textItem.objectHandle.backgroundColor - } + color: "black" //objectHandle.backgroundColor + MonoText { + id: textElement + anchors.fill: parent + text: objectHandle.text + color: "white" //objectHandle.foregroundColor + font.family: textItem.font.family + font.pixelSize: textItem.font.pixelSize + font.pointSize: textItem.font.pointSize + font.bold: objectHandle.bold + font.underline: objectHandle.underline + latin: objectHandle.latin - Text { - id: textElement - anchors.fill: parent - text: objectHandle.text - color: "white" - font: textItem.font - textFormat: Text.PlainText - } - - Connections { - target: objectHandle - - onIndexChanged: { - textItem.x = objectHandle.index * textItem.fontWidth; + SequentialAnimation { + running: objectHandle.blinking + loops: Animation.Infinite + onRunningChanged: { + if (running === false) + textElement.opacity = 1 + } + NumberAnimation { + target: textElement + property: "opacity" + to: 0 + duration: 250 + } + NumberAnimation { + target: textElement + property: "opacity" + to: 1 + duration: 250 + } + } } } - //Component.onCompleted: { - // //color = randomBg(); - //} - //function randomBg() - //{ - // var hex1=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F") - // var hex2=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F") - // var hex3=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F") - // var hex4=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F") - // var hex5=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F") - // var hex6=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F") - // var bg="#"+hex1[Math.floor(Math.random()*hex1.length)]+hex2[Math.floor(Math.random()*hex2.length)]+hex3[Math.floor(Math.random()*hex3.length)]+hex4[Math.floor(Math.random()*hex4.length)]+hex5[Math.floor(Math.random()*hex5.length)]+hex6[Math.floor(Math.random()*hex6.length)] - // return bg - //} } diff --git a/qml/cool-old-term/main.qml b/qml/cool-old-term/main.qml index 14acab0..a4fe3b4 100644 --- a/qml/cool-old-term/main.qml +++ b/qml/cool-old-term/main.qml @@ -229,13 +229,12 @@ ApplicationWindow{ TerminalScreen { id: terminal - anchors.centerIn: parent - width: mainwindow.width - height: mainwindow.height - visible: false + anchors.fill: parent //FIXME: Ugly forced clear terminal at the beginning - Component.onCompleted: terminal.screen.sendKey("l", 76, 67108864); + Component.onCompleted: { + terminal.screen.sendKey("l", 76, 67108864); + } } RadialGradient{ diff --git a/yat b/yat deleted file mode 160000 index fb2266d..0000000 --- a/yat +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fb2266d7a1ef32e36f6c74f986fa831d1fc73588 diff --git a/yat/README b/yat/README new file mode 100644 index 0000000..c95e729 --- /dev/null +++ b/yat/README @@ -0,0 +1,8 @@ +forked at 8c3d6c85c3dc981bca817bd9052a693570e26e6e + +YAT is a terminal emulator written in qml and c++ + +The main goal of the project was to find out if it was possible to use qml to +write a terminal emulator which performed on par with xterm and konsole. + +Turns out, it's possible. diff --git a/yat/backend/backend.pri b/yat/backend/backend.pri new file mode 100644 index 0000000..ec13864 --- /dev/null +++ b/yat/backend/backend.pri @@ -0,0 +1,41 @@ +DEPENDPATH += $$PWD +INCLUDEPATH += $$PWD + +LIBS += -lutil + +CONFIG += c++11 + +MOC_DIR = .moc +OBJECTS_DIR = .obj + +HEADERS += \ + $$PWD/yat_pty.h \ + $$PWD/text.h \ + $$PWD/controll_chars.h \ + $$PWD/parser.h \ + $$PWD/screen.h \ + $$PWD/block.h \ + $$PWD/color_palette.h \ + $$PWD/text_style.h \ + $$PWD/screen_data.h \ + $$PWD/cursor.h \ + $$PWD/nrc_text_codec.h \ + $$PWD/scrollback.h \ + $$PWD/utf8_decoder.h \ + $$PWD/selection.h + +SOURCES += \ + $$PWD/yat_pty.cpp \ + $$PWD/text.cpp \ + $$PWD/controll_chars.cpp \ + $$PWD/parser.cpp \ + $$PWD/screen.cpp \ + $$PWD/block.cpp \ + $$PWD/color_palette.cpp \ + $$PWD/text_style.cpp \ + $$PWD/screen_data.cpp \ + $$PWD/cursor.cpp \ + $$PWD/nrc_text_codec.cpp \ + $$PWD/scrollback.cpp \ + $$PWD/selection.cpp + diff --git a/yat/backend/block.cpp b/yat/backend/block.cpp new file mode 100644 index 0000000..6f4ce69 --- /dev/null +++ b/yat/backend/block.cpp @@ -0,0 +1,557 @@ +/******************************************************************************* + * Copyright (c) 2012 Jørgen Lind + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + ******************************************************************************/ + +#include "block.h" + +#include "text.h" +#include "screen.h" + +#include +#include + +#include + +#include + +Block::Block(Screen *screen) + : m_screen(screen) + , m_line(0) + , m_new_line(-1) + , m_screen_index(0) + , m_width(m_screen->width()) + , m_visible(true) + , m_changed(true) + , m_only_latin(true) +{ + clear(); +} + +Block::~Block() +{ + for (int i = 0; i < m_style_list.size(); i++) { + m_style_list[i].releaseTextSegment(m_screen); + } +} + +Screen *Block::screen() const +{ + return m_screen; +} + +void Block::clear() +{ + m_text_line.clear(); + + for (int i = 0; i < m_style_list.size(); i++) { + m_style_list[i].releaseTextSegment(m_screen); + } + + m_style_list.clear(); + + m_only_latin = true; + m_changed = true; +} + +void Block::clearToEnd(int from) +{ + clearCharacters(from, m_text_line.size() - 1); +} + +void Block::clearCharacters(int from, int to) +{ + if (from > m_text_line.size()) + return; + + QString empty(to+1-from, QChar(' ')); + const TextStyle &defaultTextStyle = m_screen->defaultTextStyle(); + replaceAtPos(from, empty, defaultTextStyle); +} + +void Block::deleteCharacters(int from, int to) +{ + m_changed = true; + + int removed = 0; + const int size = (to + 1) - from; + bool found = false; + + int last_index = -1; + + for (int i = 0; i < m_style_list.size(); i++) { + TextStyleLine ¤t_style = m_style_list[i]; + last_index = i; + if (found) { + current_style.start_index -= removed; + current_style.end_index -= removed; + current_style.index_dirty = true; + if (removed != size) { + int current_style_size = current_style.end_index + 1 - current_style.start_index; + if (current_style_size <= size - removed) { + removed += current_style.end_index + 1 - current_style.start_index; + current_style.releaseTextSegment(m_screen); + m_style_list.remove(i); + i--; + } else { + current_style.end_index -= size - removed; + removed = size; + } + } + } else { + if (current_style.start_index <= from && current_style.end_index >= from) { + found = true; + int left_in_style = (current_style.end_index + 1) - from; + int subtract = std::min(left_in_style, size); + current_style.end_index -= subtract; + current_style.text_dirty = true; + removed = subtract; + if (current_style.end_index < current_style.start_index) { + current_style.releaseTextSegment(m_screen); + m_style_list.remove(i); + i--; + } + } + } + } + + if (last_index >= 0) { + TextStyleLine &last_modified = m_style_list[last_index]; + TextStyle defaultStyle = m_screen->defaultTextStyle(); + if (last_modified.isCompatible(defaultStyle)) { + last_modified.end_index += size; + last_modified.text_dirty = true; + } else { + m_style_list.insert(last_index + 1, TextStyleLine(defaultStyle, + last_modified.end_index + 1, last_modified.end_index + size)); + } + } + + m_text_line.remove(from, size); +} + +void Block::deleteToEnd(int from) +{ + deleteCharacters(from, m_text_line.size() - 1); +} + +void Block::deleteLines(int from) +{ + if (from > lineCount()) + return; +} + +void Block::replaceAtPos(int pos, const QString &text, const TextStyle &style, bool only_latin) +{ + m_changed = true; + m_only_latin = m_only_latin && only_latin; + + if (pos >= m_text_line.size()) { + if (pos > m_text_line.size()) { + int old_size = m_text_line.size(); + QString filling(pos - m_text_line.size(), QChar(' ')); + m_text_line.append(filling); + m_style_list.append(TextStyleLine(m_screen->defaultTextStyle(), old_size, old_size + filling.size() -1)); + } + m_text_line.append(text); + m_style_list.append(TextStyleLine(style, pos, pos + text.size()-1)); + return; + } else if (pos + text.size() > m_text_line.size()) { + m_style_list.append(TextStyleLine(m_screen->defaultTextStyle(), pos + text.size() - m_text_line.size(), pos + text.size() -1)); + } + + m_text_line.replace(pos,text.size(),text); + bool found = false; + for (int i = 0; i < m_style_list.size(); i++) { + TextStyleLine ¤t_style = m_style_list[i]; + if (found) { + if (current_style.end_index <= pos + text.size() - 1) { + current_style.releaseTextSegment(m_screen); + m_style_list.remove(i); + i--; + } else if (current_style.start_index <= pos + text.size()) { + current_style.start_index = pos + text.size(); + current_style.style_dirty = true; + current_style.text_dirty = true; + current_style.index_dirty = true; + } else { + break; + } + } else if (pos >= current_style.start_index && pos <= current_style.end_index) { + found = true; + if (pos + text.size() -1 <= current_style.end_index) { + if (current_style.isCompatible(style)) { + current_style.text_dirty = true; + } else { + if (current_style.start_index == pos && current_style.end_index == pos + text.size() - 1) { + current_style.setStyle(style); + current_style.text_dirty = true; + current_style.style_dirty = true; + } else if (current_style.start_index == pos) { + current_style.start_index = pos + text.size(); + current_style.text_dirty = true; + m_style_list.insert(i, TextStyleLine(style,pos, pos+text.size() -1)); + } else if (current_style.end_index == pos + text.size() - 1) { + current_style.end_index = pos - 1; + current_style.text_dirty = true; + m_style_list.insert(i+1, TextStyleLine(style,pos, pos + text.size() - 1)); + } else { + int old_end = current_style.end_index; + current_style.end_index = pos - 1; + current_style.text_dirty = true; + m_style_list.insert(i+1, TextStyleLine(style,pos, pos + text.size() - 1)); + if (pos + text.size() < m_text_line.size()) { + m_style_list.insert(i+2, TextStyleLine(current_style,pos + text.size(), old_end)); + } + } + } + break; + } else { + if (current_style.isCompatible(style)) { + current_style.end_index = pos + text.size() - 1; + current_style.text_dirty = true; + } else { + if (current_style.start_index == pos) { + if (i > 0 && m_style_list.at(i-1).isCompatible(style)) { + TextStyleLine &previous_style = m_style_list[i -1]; + previous_style.end_index+= text.size(); + previous_style.text_dirty = true; + current_style.releaseTextSegment(m_screen); + m_style_list.remove(i); + i--; + } else { + current_style.end_index = pos + text.size() - 1; + current_style.style = style.style; + current_style.forground = style.forground; + current_style.background = style.background; + current_style.text_dirty = true; + current_style.style_dirty = true; + current_style.index_dirty = true; + } + } else { + current_style.end_index = pos - 1; + current_style.text_dirty = true; + m_style_list.insert(i+1, TextStyleLine(style, pos, pos + text.size() -1)); + i++; + } + } + } + } + } +} + +void Block::insertAtPos(int pos, const QString &text, const TextStyle &style, bool only_latin) +{ + m_changed = true; + m_only_latin = m_only_latin && only_latin; + + m_text_line.insert(pos,text); + bool found = false; + + for (int i = 0; i < m_style_list.size(); i++) { + TextStyleLine ¤t_style = m_style_list[i]; + if (found) { + current_style.start_index += text.size(); + current_style.end_index += text.size(); + current_style.index_dirty = true; + if (current_style.start_index >= m_text_line.size()) { + current_style.releaseTextSegment(m_screen); + m_style_list.remove(i); + i--; + } else if (current_style.end_index >= m_text_line.size()) { + current_style.end_index = m_text_line.size()-1; + } + } else if (pos >= current_style.start_index && pos <= current_style.end_index) { + found = true; + if (current_style.start_index == pos) { + current_style.start_index += text.size(); + current_style.end_index += text.size(); + current_style.index_dirty = true; + m_style_list.insert(i, TextStyleLine(style, pos, pos+ text.size() - 1)); + i++; + } else if (current_style.end_index == pos) { + current_style.end_index--; + current_style.text_dirty = true; + m_style_list.insert(i+1, TextStyleLine(style, pos, pos+ text.size() - 1)); + i++; + } else { + int old_end = current_style.end_index; + current_style.end_index = pos -1; + current_style.text_dirty = true; + m_style_list.insert(i+1, TextStyleLine(style, pos, pos + text.size() - 1)); + if (pos + text.size() < m_text_line.size()) { + int segment_end = std::min(m_text_line.size() -1, old_end + text.size()); + m_style_list.insert(i+2, TextStyleLine(current_style, pos + text.size(), segment_end)); + i+=2; + } else { + i++; + } + } + } + } +} + +QString *Block::textLine() +{ + return &m_text_line; +} + +void Block::setVisible(bool visible) +{ + if (visible != m_visible) { + m_changed = true; + m_visible = visible; + for (int i = 0; i < m_style_list.size(); i++) { + if (m_style_list.at(i).text_segment) { + m_style_list.at(i).text_segment->setVisible(visible); + } + } + } +} + +bool Block::visible() const +{ + return m_visible; +} + +Block *Block::split(int line) +{ + if (line >= lineCount()) + return nullptr; + m_changed = true; + Block *to_return = new Block(m_screen); + int start_index = line * m_width; + for (int i = 0; i < m_style_list.size(); i++) { + ensureStyleAlignWithLines(i); + TextStyleLine ¤t_style = m_style_list[i]; + if (current_style.start_index >= start_index) { + current_style.start_index -= start_index; + current_style.old_index = current_style.start_index - 1; + current_style.end_index -= start_index; + current_style.index_dirty = true; + current_style.text_dirty = true; + current_style.index_dirty = true; + to_return->m_style_list.append(TextStyleLine(current_style, current_style.start_index, + current_style.end_index)); + m_style_list.remove(i); + i--; + } + } + to_return->m_text_line = m_text_line.mid(start_index, m_text_line.size() - start_index); + m_text_line.remove(start_index, m_text_line.size() - start_index); + return to_return; +} + +Block *Block::takeLine(int line) +{ + if (line >= lineCount()) + return nullptr; + m_changed = true; + Block *to_return = new Block(m_screen); + int start_index = line * m_width; + int end_index = start_index + (m_width - 1); + for (int i = 0; i < m_style_list.size(); i++) { + ensureStyleAlignWithLines(i); + TextStyleLine ¤t_style = m_style_list[i]; + if (current_style.start_index >= start_index && current_style.end_index <= end_index) { + current_style.releaseTextSegment(m_screen); + current_style.start_index -= start_index; + current_style.end_index -= start_index; + current_style.index_dirty = true; + to_return->m_style_list.append(TextStyleLine(current_style, current_style.start_index, + current_style.end_index)); + m_style_list.remove(i); + i--; + } else if (current_style.start_index > end_index) { + current_style.start_index -= (end_index + 1) - start_index; + current_style.end_index -= (end_index + 1) - start_index; + current_style.index_dirty = true; + current_style.text_dirty = true; + } + } + to_return->m_text_line = m_text_line.mid(start_index, m_width); + m_text_line.remove(start_index, m_width); + return to_return; +} + +void Block::removeLine(int line) +{ + if (line >= lineCount()) + return; + + m_changed = true; + int start_index = line * m_width; + int end_index = start_index + (m_width - 1); + for (int i = 0; i < m_style_list.size(); i++) { + ensureStyleAlignWithLines(i); + TextStyleLine ¤t_style = m_style_list[i]; + if (current_style.start_index >= start_index && current_style.end_index <= end_index) { + current_style.releaseTextSegment(m_screen); + m_style_list.remove(i); + i--; + } else if (current_style.start_index > end_index) { + current_style.start_index -= (end_index + 1) - start_index; + current_style.end_index -= (end_index + 1) - start_index; + current_style.index_dirty = true; + current_style.text_dirty = true; + } + } + m_text_line.remove(start_index, m_width); +} + +void Block::moveLinesFromBlock(Block *block, int start_line, int count) +{ + Q_ASSERT(block); + Q_ASSERT(block->lineCount() >= start_line + count); + + int start_char = block->width() * start_line; + int end_char = (block->width() * (start_line + count)) - 1; + + for (int i = 0; i < block->m_style_list.size(); i++) { + TextStyleLine ¤t_style = block->m_style_list[i]; + if (current_style.start_index >= start_char && current_style.end_index <= end_char) { + current_style.start_index += (-start_char + m_text_line.size()); + current_style.end_index += (-start_char + m_text_line.size()); + current_style.releaseTextSegment(m_screen); + m_style_list.append(TextStyleLine(current_style, current_style.start_index, + current_style.end_index)); + block->m_style_list.remove(i); + i--; + } else if (current_style.start_index > end_char) { + current_style.start_index -= (end_char + 1) - start_char; + current_style.end_index -= (end_char + 1) - start_char; + current_style.index_dirty = true; + current_style.text_dirty = true; + } + } + + m_text_line.append(block->m_text_line.mid(start_char, (end_char + 1) - start_char)); + block->m_text_line.remove(start_char, (end_char + 1) - start_char); + m_changed = true; + block->m_changed = true; +} + +void Block::dispatchEvents() +{ + if (!m_changed) { + return; + } + + mergeCompatibleStyles(); + + for (int i = 0; i < m_style_list.size(); i++) { + ensureStyleAlignWithLines(i); + TextStyleLine ¤t_style = m_style_list[i]; + if (current_style.text_segment == 0) { + current_style.text_segment = m_screen->createTextSegment(current_style); + current_style.text_segment->setLine(m_new_line, m_width, &m_text_line); + } else if (m_new_line != m_line) { + current_style.text_segment->setLine(m_new_line, m_width, &m_text_line); + } + + if (current_style.style_dirty) { + current_style.text_segment->setTextStyle(current_style); + current_style.style_dirty = false; + } + + if (current_style.index_dirty || current_style.text_dirty) { + current_style.text_segment->setStringSegment(current_style.start_index, current_style.end_index, current_style.text_dirty); + current_style.index_dirty = false; + current_style.text_dirty = false; + } + + current_style.text_segment->setLatin(m_only_latin); + current_style.text_segment->dispatchEvents(); + } + + m_changed = false; + m_line = m_new_line; + +} + +void Block::releaseTextObjects() +{ + m_changed = true; + for (int i = 0; i < m_style_list.size(); i++) { + TextStyleLine ¤tStyleLine = m_style_list[i]; + currentStyleLine.releaseTextSegment(m_screen); + currentStyleLine.text_dirty = true; + currentStyleLine.style_dirty = true; + } +} + +QVector Block::style_list() +{ + return m_style_list; +} + +void Block::printStyleList() const +{ + QDebug debug = qDebug(); + printStyleList(debug); +} + +void Block::printStyleList(QDebug &debug) const +{ + QString text_line = m_text_line; + debug << " " << m_line << lineCount() << m_text_line.size() << (void *) this << text_line << "\n"; debug << "\t"; + for (int i= 0; i < m_style_list.size(); i++) { + debug << m_style_list.at(i); + } +} + +void Block::printStyleListWidthText() const +{ + QString text_line = m_text_line; + for (int i= 0; i < m_style_list.size(); i++) { + const TextStyleLine ¤tStyle = m_style_list.at(i); + QDebug debug = qDebug(); + debug << m_text_line.mid(currentStyle.start_index, (currentStyle.end_index + 1) - currentStyle.start_index) << currentStyle; + } +} + +void Block::mergeCompatibleStyles() +{ + for (int i = 1; i < m_style_list.size(); i++) { + TextStyleLine ¤t = m_style_list[i]; + if (m_style_list.at(i - 1).isCompatible(current) && + current.start_index % m_width != 0) { + TextStyleLine &prev = m_style_list[i-1]; + prev.end_index = current.end_index; + prev.text_dirty = true; + current.releaseTextSegment(m_screen); + m_style_list.remove(i); + i--; + } + } +} + +void Block::ensureStyleAlignWithLines(int i) +{ + int start_line = m_style_list[i].start_index / m_width; + int end_line = m_style_list[i].end_index / m_width; + if (start_line != end_line) { + int remainder_start_line = ((m_width * (start_line + 1))-1) - m_style_list[i].start_index; + int next_line_end_index = m_style_list[i].end_index; + m_style_list[i].end_index = m_style_list[i].start_index + remainder_start_line; + m_style_list.insert(i + 1, TextStyleLine(m_style_list[i], m_style_list[i].end_index + 1, next_line_end_index)); + } +} diff --git a/yat/backend/block.h b/yat/backend/block.h new file mode 100644 index 0000000..c759542 --- /dev/null +++ b/yat/backend/block.h @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#ifndef BLOCK_H +#define BLOCK_H + +#include + +#include "text_style.h" + +class Text; +class Screen; + +class Block +{ +public: + Block(Screen *screen); + ~Block(); + + Q_INVOKABLE Screen *screen() const; + + void clear(); + void clearToEnd(int from); + void clearCharacters(int from, int to); + void deleteCharacters(int from, int to); + void deleteToEnd(int from); + void deleteLines(int from); + + void replaceAtPos(int i, const QString &text, const TextStyle &style, bool only_latin = true); + void insertAtPos(int i, const QString &text, const TextStyle &style, bool only_latin = true); + + void setScreenIndex(int index) { m_screen_index = index; } + int screenIndex() const { return m_screen_index; } + size_t line() { return m_new_line; } + void setLine(size_t line) { + if (line != m_new_line) { + m_changed = true; + m_new_line = line; + } + } + + QString *textLine(); + int textSize() { return m_text_line.size(); } + + int width() const { return m_width; } + void setWidth(int width) { m_changed = true; m_width = width; } + int lineCount() const { return (std::max((m_text_line.size() - 1),0) / m_width) + 1; } + int lineCountAfterModified(int from_char, int text_size, bool replace) { + int new_size = replace ? std::max(from_char + text_size, m_text_line.size()) + : std::max(from_char, m_text_line.size()) + text_size; + return ((new_size - 1) / m_width) + 1; + } + + void setVisible(bool visible); + bool visible() const; + + Block *split(int line); + Block *takeLine(int line); + void removeLine(int line); + + void moveLinesFromBlock(Block *block, int start_line, int count); + + void dispatchEvents(); + void releaseTextObjects(); + + QVector style_list(); + + void printStyleList() const; + void printStyleList(QDebug &debug) const; + void printStyleListWidthText() const; + +private: + void mergeCompatibleStyles(); + void ensureStyleAlignWithLines(int i); + Screen *m_screen; + QString m_text_line; + QVector m_style_list; + size_t m_line; + size_t m_new_line; + int m_screen_index; + + int m_width; + + bool m_visible; + bool m_changed; + bool m_only_latin; +}; + +#endif // BLOCK_H diff --git a/yat/backend/character_sets.h b/yat/backend/character_sets.h new file mode 100644 index 0000000..1d7128c --- /dev/null +++ b/yat/backend/character_sets.h @@ -0,0 +1,265 @@ +/****************************************************************************** +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#include + +static const QChar dec_special_graphics_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0020, + /*0x60*/ 0x25c6,0x2592,0x2409,0x240c,0x240d,0x240a,0x00b0,0x00b1, + /*0x68*/ 0x2424,0x240b,0x2518,0x2510,0x250c,0x2514,0x253c,0x23ba, + /*0x70*/ 0x23bb,0x2500,0x23bc,0x23bd,0x251c,0x2524,0x2534,0x252c, + /*0x78*/ 0x2502,0x2264,0x2265,0x03c0,0x2260,0x00a3,0x00b7,0x0000, +}; + +static const QChar nrc_british_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x00a3,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x60*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x68*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x70*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x78*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, +}; + +static const QChar nrc_norwegian_danish_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x00c4,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x00c6,0x00d8,0x00c5,0x00dc,0x0000, + /*0x60*/ 0x00e4,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x68*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x70*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x78*/ 0x0000,0x0000,0x0000,0x00e6,0x00f8,0x00e5,0x00fc,0x0000, +}; + +static const QChar nrc_dutch_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x00a3,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x00be,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x0133,0x00bd,0x007c,0x0000,0x0000, + /*0x60*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x68*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x70*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x78*/ 0x0000,0x0000,0x0000,0x00a8,0x0066,0x00bc,0x00b4,0x0000, +}; + +static const QChar nrc_finnish_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x00c4,0x00d6,0x00c5,0x00dc,0x0000, + /*0x60*/ 0x00e9,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x68*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x70*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x78*/ 0x0000,0x0000,0x0000,0x00e4,0x00f6,0x00e5,0x00fc,0x0000, +}; + +static const QChar nrc_french_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x00a3,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x00e0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x00b0,0x00e7,0x00a7,0x0000,0x0000, + /*0x60*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x68*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x70*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x78*/ 0x0000,0x0000,0x0000,0x00e9,0x00f9,0x00e8,0x00a8,0x0000, +}; + +static const QChar nrc_french_canadian_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x00e0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x00e2,0x00e7,0x00ea,0x00ee,0x0000, + /*0x60*/ 0x00f4,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x68*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x70*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x78*/ 0x0000,0x0000,0x0000,0x00e9,0x00f9,0x00e8,0x00fb,0x0000, +}; + +static const QChar nrc_german_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x00a7,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x00c4,0x00d6,0x00dc,0x0000,0x0000, + /*0x60*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x68*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x70*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x78*/ 0x0000,0x0000,0x0000,0x00e4,0x00f6,0x00fc,0x00df,0x0000, +}; + +static const QChar nrc_italian_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x00a3,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x00a7,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x00b0,0x00e7,0x00e9,0x0000,0x0000, + /*0x60*/ 0x00f9,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x68*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x70*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x78*/ 0x0000,0x0000,0x0000,0x00e0,0x00f2,0x00e8,0x00ec,0x0000, +}; + +static const QChar nrc_spanish_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x00a3,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x00a7,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x00a1,0x00d1,0x00bf,0x0000,0x0000, + /*0x60*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x68*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x70*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x78*/ 0x0000,0x0000,0x0000,0x00b0,0x00f1,0x00e7,0x0000,0x0000, +}; + +static const QChar nrc_swedish_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x00c9,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x00c4,0x00d6,0x00c5,0x00dc,0x0000, + /*0x60*/ 0x00e9,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x68*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x70*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x78*/ 0x0000,0x0000,0x0000,0x00e4,0x00f6,0x00e5,0x00fc,0x0000, +}; + +static const QChar nrc_swiss_char_set[] = +{ + /*0x00*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x08*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x10*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x18*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x20*/ 0x0000,0x0000,0x0000,0x00f9,0x0000,0x0000,0x0000,0x0000, + /*0x28*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x30*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x38*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x40*/ 0x00e0,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x48*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x50*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x58*/ 0x0000,0x0000,0x0000,0x00e9,0x00e7,0x00ea,0x00ee,0x00e8, + /*0x60*/ 0x00f4,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x68*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x70*/ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, + /*0x78*/ 0x0000,0x0000,0x0000,0x00e4,0x00f6,0x00fc,0x00fb,0x0000, +}; + diff --git a/yat/backend/color_palette.cpp b/yat/backend/color_palette.cpp new file mode 100644 index 0000000..a97b9c6 --- /dev/null +++ b/yat/backend/color_palette.cpp @@ -0,0 +1,66 @@ +#include "color_palette.h" + +#include +ColorPalette::ColorPalette(QObject *parent) + : QObject(parent) + , m_normalColors(numberOfColors) + , m_lightColors(numberOfColors) + , m_intenseColors(numberOfColors) + , m_inverse_default(false) +{ + m_normalColors[0].setRgb(0,0,0); + m_normalColors[1].setRgb(194,54,33); + m_normalColors[2].setRgb(37,188,36); + m_normalColors[3].setRgb(173,173,39); + m_normalColors[4].setRgb(63,84,255); + m_normalColors[5].setRgb(211,56,211); + m_normalColors[6].setRgb(51,187,199); + m_normalColors[7].setRgb(229,229,229); + m_normalColors[8].setRgb(178,178,178); + m_normalColors[9].setRgb(0,0,0); + + m_lightColors[0].setRgb(129,131,131); + m_lightColors[1].setRgb(252,57,31); + m_lightColors[2].setRgb(49,231,34); + m_lightColors[3].setRgb(234,236,35); + m_lightColors[4].setRgb(88,51,255); + m_lightColors[5].setRgb(249,53,248); + m_lightColors[6].setRgb(20,240,240); + m_lightColors[7].setRgb(233,233,233); + m_lightColors[8].setRgb(220,220,220); + m_lightColors[9].setRgb(50,50,50); + +} + +QColor ColorPalette::color(ColorPalette::Color color, bool bold) const +{ + if (m_inverse_default) { + if (color == DefaultForground) + color = DefaultBackground; + else if (color == DefaultBackground) + color = DefaultForground; + } + if (bold) + return m_lightColors.at(color); + + return m_normalColors.at(color); +} + +QColor ColorPalette::normalColor(ColorPalette::Color color) const +{ + return this->color(color, false); +} + +QColor ColorPalette::lightColor(ColorPalette::Color color) const +{ + return this->color(color,true); +} + +void ColorPalette::setInverseDefaultColors(bool inverse) +{ + bool emit_changed = inverse != m_inverse_default; + if (emit_changed) { + m_inverse_default = inverse; + emit changed(); + } +} diff --git a/yat/backend/color_palette.h b/yat/backend/color_palette.h new file mode 100644 index 0000000..bb246e7 --- /dev/null +++ b/yat/backend/color_palette.h @@ -0,0 +1,43 @@ +#ifndef COLOR_PALETTE_H +#define COLOR_PALETTE_H + +#include + +#include + +class ColorPalette : public QObject +{ +Q_OBJECT +public: + ColorPalette(QObject *parent = 0); + + enum Color { + Black, + Red, + Green, + Yellow, + Blue, + Magenta, + Cyan, + White, + DefaultForground, + DefaultBackground, + numberOfColors + }; + + QColor color(Color color, bool bold) const; + QColor normalColor(Color color) const; + QColor lightColor(Color color) const; + + void setInverseDefaultColors(bool inverse); +signals: + void changed(); +private: + QVector m_normalColors; + QVector m_lightColors; + QVector m_intenseColors; + + bool m_inverse_default; +}; + +#endif // COLOR_PALETTE_H diff --git a/yat/backend/controll_chars.cpp b/yat/backend/controll_chars.cpp new file mode 100644 index 0000000..4b5c83f --- /dev/null +++ b/yat/backend/controll_chars.cpp @@ -0,0 +1,798 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ +#include "controll_chars.h" + +namespace C0 { +QDebug operator<<(QDebug debug, C0 character) { + bool insert_space = debug.autoInsertSpaces(); + debug.setAutoInsertSpaces(false); + debug << "C0::"; + switch (character) { + case NUL: + debug << "NUL"; + break; + case SOH: + debug << "SOH"; + break; + case STX: + debug << "STX"; + break; + case ETX: + debug << "ETX"; + break; + case EOT: + debug << "EOT"; + break; + case ENQ: + debug << "ENQ"; + break; + case ACK: + debug << "ACK"; + break; + case BEL: + debug << "BEL"; + break; + case BS: + debug << "BS"; + break; + case HT: + debug << "HT"; + break; + case LF: + debug << "LF"; + break; + case VT: + debug << "VT"; + break; + case FF: + debug << "FF"; + break; + case CR: + debug << "CR"; + break; + case SOorLS1: + debug << "SOorLS1"; + break; + case SIorLS0: + debug << "SIorLS0"; + break; + case DLE: + debug << "DLE"; + break; + case DC1: + debug << "DC1"; + break; + case DC2: + debug << "DC2"; + break; + case DC3: + debug << "DC3"; + break; + case DC4: + debug << "DC4"; + break; + case NAK: + debug << "NAK"; + break; + case SYN: + debug << "SYN"; + break; + case ETB: + debug << "ETB"; + break; + case CAN: + debug << "CAN"; + break; + case EM: + debug << "EM"; + break; + case SUB: + debug << "SUB"; + break; + case ESC: + debug << "ESC"; + break; + case IS4: + debug << "IS4"; + break; + case IS3: + debug << "IS3"; + break; + case IS2: + debug << "IS2"; + break; + case IS1: + debug << "IS1"; + break; + case C0_END: + debug << "C0_END"; + break; + default: + debug << qPrintable(QString("0x%1").arg(character,0,16)); + break; + } + debug.setAutoInsertSpaces(insert_space); + return debug; +} +} + +namespace C1_7bit { +QDebug operator<<(QDebug debug, C1_7bit character) { + bool insert_space = debug.autoInsertSpaces(); + debug.setAutoInsertSpaces(false); + debug << "C1_7bit::"; + switch(character) { + case ESC: + debug << "ESC"; + break; + case SCS_G0: + debug << "SCS_G0"; + break; + case SCS_G1: + debug << "SCS_G1"; + break; + case SCS_G2: + debug << "SCS_G2"; + break; + case SCS_G3: + debug << "SCS_G3"; + break; + case DECSC: + debug << "DECSC"; + break; + case DECRC: + debug << "DECRC"; + break; + case NOT_DEFINED: + debug << "NOT_DEFINED"; + break; + case NOT_DEFINED1: + debug << "NOT_DEFINED1"; + break; + case BPH: + debug << "BPH"; + break; + case NBH: + debug << "NBH"; + break; + case IND: + debug << "IND"; + break; + case NEL: + debug << "NEL"; + break; + case SSA: + debug << "SSA"; + break; + case ESA: + debug << "ESA"; + break; + case HTS: + debug << "HTS"; + break; + case HTJ: + debug << "HTJ"; + break; + case VTS: + debug << "VTS"; + break; + case PLD: + debug << "PLD"; + break; + case PLU: + debug << "PLU"; + break; + case RI : + debug << "RI "; + break; + case SS2: + debug << "SS2"; + break; + case SS3: + debug << "SS3"; + break; + case DCS: + debug << "DCS"; + break; + case PU1: + debug << "PU1"; + break; + case PU2: + debug << "PU2"; + break; + case STS: + debug << "STS"; + break; + case CCH: + debug << "CCH"; + break; + case MW : + debug << "MW "; + break; + case SPA: + debug << "SPA"; + break; + case EPA: + debug << "EPA"; + break; + case SOS: + debug << "SOS"; + break; + case NOT_DEFINED3: + debug << "NOT_DEFINED3"; + break; + case SCI: + debug << "SCI"; + break; + case CSI: + debug << "CSI"; + break; + case ST : + debug << "ST "; + break; + case OSC: + debug << "OSC"; + break; + case PM : + debug << "PM "; + break; + case APC: + debug << "APC"; + break; + case C1_7bit_Stop: + debug << "C1_7bit_Stop"; + break; + default: + debug << qPrintable(QString("0x%1").arg(character,0,16)); + break; + } + debug.setAutoInsertSpaces(insert_space); + return debug; +} +} + +namespace C1_8bit { +QDebug operator<<(QDebug debug, C1_8bit character) { + bool insert_space = debug.autoInsertSpaces(); + debug.setAutoInsertSpaces(false); + debug << "C1_8bit::"; + switch(character) { + case NOT_DEFINED: + debug << "NOT_DEFINED"; + break; + case NOT_DEFINED1: + debug << "NOT_DEFINED1"; + break; + case BPH: + debug << "BPH"; + break; + case NBH: + debug << "NBH"; + break; + case NOT_DEFINED2: + debug << "NOT_DEFINED2"; + break; + case NEL: + debug << "NEL"; + break; + case SSA: + debug << "SSA"; + break; + case ESA: + debug << "ESA"; + break; + case HTS: + debug << "HTS"; + break; + case HTJ: + debug << "HTJ"; + break; + case VTS: + debug << "VTS"; + break; + case PLD: + debug << "PLD"; + break; + case PLU: + debug << "PLU"; + break; + case RI : + debug << "RI "; + break; + case SS2: + debug << "SS2"; + break; + case SS3: + debug << "SS3"; + break; + case DCS: + debug << "DCS"; + break; + case PU1: + debug << "PU1"; + break; + case PU2C1_7bit: + debug << "PU2C1_7bit"; + break; + case STS: + debug << "STS"; + break; + case CCH: + debug << "CCH"; + break; + case MW : + debug << "MW "; + break; + case SPA: + debug << "SPA"; + break; + case EPA: + debug << "EPA"; + break; + case SOS: + debug << "SOS"; + break; + case NOT_DEFINED3: + debug << "NOT_DEFINED3"; + break; + case SCI: + debug << "SCI"; + break; + case CSI: + debug << "CSI"; + break; + case ST : + debug << "ST "; + break; + case OSC: + debug << "OSC"; + break; + case PM : + debug << "PM "; + break; + case APC: + debug << "APC"; + break; + case C1_8bit_Stop: + debug << "C1_8bit_Stop"; + break; + default: + debug << qPrintable(QString("0x%1").arg(character,0,16)); + break; + } + debug.setAutoInsertSpaces(insert_space); + return debug; +} +} +namespace FinalBytesNoIntermediate { +QDebug operator<<(QDebug debug, FinalBytesNoIntermediate character) { + bool insert_space = debug.autoInsertSpaces(); + debug.setAutoInsertSpaces(false); + debug << "FinalBytesNoIntermediate::"; + switch(character) { + case ICH: + debug << "ICH"; + break; + case CUU: + debug << "CUU"; + break; + case CUD: + debug << "CUD"; + break; + case CUF: + debug << "CUF"; + break; + case CUB: + debug << "CUB"; + break; + case CNL: + debug << "CNL"; + break; + case CPL: + debug << "CPL"; + break; + case CHA: + debug << "CHA"; + break; + case CUP: + debug << "CUP"; + break; + case CHT: + debug << "CHT"; + break; + case ED: + debug << "ED"; + break; + case EL: + debug << "EL"; + break; + case IL: + debug << "IL"; + break; + case DL: + debug << "DL"; + break; + case EF: + debug << "EF"; + break; + case EA: + debug << "EA"; + break; + case DCH: + debug << "DCH"; + break; + case SSE: + debug << "SSE"; + break; + case CPR: + debug << "CPR"; + break; + case SU: + debug << "SU"; + break; + case SD: + debug << "SD"; + break; + case NP: + debug << "NP"; + break; + case PP: + debug << "PP"; + break; + case CTC: + debug << "CTC"; + break; + case ECH: + debug << "ECH"; + break; + case CVT: + debug << "CVT"; + break; + case CBT: + debug << "CBT"; + break; + case SRS: + debug << "SRS"; + break; + case PTX: + debug << "PTX"; + break; + case SDS: + debug << "SDS"; + break; + case SIMD: + debug << "SIMD"; + break; + case NOT_DEFINED: + debug << "NOT_DEFINED"; + break; + case HPA: + debug << "HPA"; + break; + case HPR: + debug << "HPR"; + break; + case REP: + debug << "REP"; + break; + case DA: + debug << "DA"; + break; + case VPA: + debug << "VPA"; + break; + case VPR: + debug << "VPR"; + break; + case HVP: + debug << "HVP"; + break; + case TBC: + debug << "TBC"; + break; + case SM: + debug << "SM"; + break; + case MC: + debug << "MC"; + break; + case HPB: + debug << "HPB"; + break; + case VPB: + debug << "VPB"; + break; + case RM: + debug << "RM"; + break; + case SGR: + debug << "SGR"; + break; + case DSR: + debug << "DSR"; + break; + case DAQ: + debug << "DAQ"; + break; + case Reserved0: + debug << "Reserved0"; + break; + case Reserved1: + debug << "Reserved1"; + break; + case DECSTBM: + debug << "DECSTBM"; + break; + case Reserved3: + debug << "Reserved3"; + break; + case Reserved4: + debug << "Reserved4"; + break; + case Reserved5: + debug << "Reserved5"; + break; + case Reserved6: + debug << "Reserved6"; + break; + case Reserved7: + debug << "Reserved7"; + break; + case Reserved8: + debug << "Reserved8"; + break; + case Reserved9: + debug << "Reserved9"; + break; + case Reserveda: + debug << "Reserveda"; + break; + case Reservedb: + debug << "Reservedb"; + break; + case Reservedc: + debug << "Reservedc"; + break; + case Reservedd: + debug << "Reservedd"; + break; + case Reservede: + debug << "Reservede"; + break; + case Reservedf: + debug << "Reservedf"; + break; + default: + debug << qPrintable(QString("0x%1").arg(character,0,16)); + break; + } + debug.setAutoInsertSpaces(insert_space); + return debug; +} +} + +namespace FinalBytesSingleIntermediate { +QDebug operator<<(QDebug debug, FinalBytesSingleIntermediate character) +{ + bool insert_space = debug.autoInsertSpaces(); + debug.setAutoInsertSpaces(false); + debug << "FinalBytesSingleIntermediate::"; + switch(character) { + case SL: + debug << "SL"; + break; + case SR: + debug << "SR"; + break; + case GSM: + debug << "GSM"; + break; + case GSS: + debug << "GSS"; + break; + case FNT: + debug << "FNT"; + break; + case TSS: + debug << "TSS"; + break; + case JFY: + debug << "JFY"; + break; + case SPI: + debug << "SPI"; + break; + case QUAD: + debug << "QUAD"; + break; + case SSU: + debug << "SSU"; + break; + case PFS: + debug << "PFS"; + break; + case SHS: + debug << "SHS"; + break; + case SVS: + debug << "SVS"; + break; + case IGS: + debug << "IGS"; + break; + case NOT_DEFINED: + debug << "NOT_DEFINED"; + break; + case IDCS: + debug << "IDCS"; + break; + case PPA: + debug << "PPA"; + break; + case PPR: + debug << "PPR"; + break; + case PPB: + debug << "PPB"; + break; + case SPD: + debug << "SPD"; + break; + case DTA: + debug << "DTA"; + break; + case SHL: + debug << "SHL"; + break; + case SLL: + debug << "SLL"; + break; + case FNK: + debug << "FNK"; + break; + case SPQR: + debug << "SPQR"; + break; + case SEF: + debug << "SEF"; + break; + case PEC: + debug << "PEC"; + break; + case SSW: + debug << "SSW"; + break; + case SACS: + debug << "SACS"; + break; + case SAPV: + debug << "SAPV"; + break; + case STAB: + debug << "STAB"; + break; + case GCC: + debug << "GCC"; + break; + case TATE: + debug << "TATE"; + break; + case TALE: + debug << "TALE"; + break; + case TAC: + debug << "TAC"; + break; + case TCC: + debug << "TCC"; + break; + case TSR: + debug << "TSR"; + break; + case SCO: + debug << "SCO"; + break; + case SRCS: + debug << "SRCS"; + break; + case SCS: + debug << "SCS"; + break; + case SLS: + debug << "SLS"; + break; + case NOT_DEFINED2: + debug << "NOT_DEFINED2"; + break; + case NOT_DEFINED3: + debug << "NOT_DEFINED3"; + break; + case SCP: + debug << "SCP"; + break; + case NOT_DEFINED4: + debug << "NOT_DEFINED4"; + break; + case NOT_DEFINED5: + debug << "NOT_DEFINED5"; + break; + case NOT_DEFINED6: + debug << "NOT_DEFINED6"; + break; + case NOT_DEFINED7: + debug << "NOT_DEFINED7"; + break; + case Reserved0: + debug << "Reserved0"; + break; + case Reserved1: + debug << "Reserved1"; + break; + case Reserved2: + debug << "Reserved2"; + break; + case Reserved3: + debug << "Reserved3"; + break; + case Reserved4: + debug << "Reserved4"; + break; + case Reserved5: + debug << "Reserved5"; + break; + case Reserved6: + debug << "Reserved6"; + break; + case Reserved7: + debug << "Reserved7"; + break; + case Reserved8: + debug << "Reserved8"; + break; + case Reserved9: + debug << "Reserved9"; + break; + case Reserveda: + debug << "Reserveda"; + break; + case Reservedb: + debug << "Reservedb"; + break; + case Reservedc: + debug << "Reservedc"; + break; + case Reservedd: + debug << "Reservedd"; + break; + case Reservedf: + debug << "Reservedf"; + break; + default: + debug << qPrintable(QString("0x%1").arg(character,0,16)); + break; + } + debug.setAutoInsertSpaces(insert_space); + return debug; +} +} + diff --git a/yat/backend/controll_chars.h b/yat/backend/controll_chars.h new file mode 100644 index 0000000..3098583 --- /dev/null +++ b/yat/backend/controll_chars.h @@ -0,0 +1,299 @@ +/****************************************************************************** +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#ifndef CONTROLL_CHARS_H +#define CONTROLL_CHARS_H + +//This is taken largely from Standard ECMA-48 +//http://www.ecma-international.org/publications/standards/Ecma-048.htm +//Also to heres a few handy references +//http://invisible-island.net/xterm/ctlseqs/ctlseqs.html +//http://www.vt100.net/docs/vt100-ug/chapter3.html + +#include + +namespace C0 { +enum C0 { + NUL = 0x00, + SOH = 0x01, + STX = 0x02, + ETX = 0x03, + EOT = 0x04, + ENQ = 0x05, + ACK = 0x06, + BEL = 0x07, + BS = 0x08, + HT = 0x09, + LF = 0x0a, + VT = 0x0b, + FF = 0x0c, + CR = 0x0d, + SOorLS1 = 0x0e, + SIorLS0 = 0x0f, + DLE = 0x10, + DC1 = 0x11, + DC2 = 0x12, + DC3 = 0x13, + DC4 = 0x14, + NAK = 0x15, + SYN = 0x16, + ETB = 0x17, + CAN = 0x18, + EM = 0x19, + SUB = 0x1a, + ESC = 0x1b, + IS4 = 0x1c, + IS3 = 0x1d, + IS2 = 0x1e, + IS1 = 0x1f, + C0_END = 0x20 +}; +QDebug operator<<(QDebug debug, C0 character); +} + +namespace C1_7bit { +enum C1_7bit { + C1_7bit_Start = 0x1b, + ESC = 0x1b, + SCS_G0 = 0x28, + SCS_G1 = 0x29, + SCS_G2 = 0x2a, + SCS_G3 = 0x2b, + DECSC = 0x37, + DECRC = 0x38, + NOT_DEFINED = 0x40, + NOT_DEFINED1 = 0x41, + BPH = 0x42, + NBH = 0x43, + IND = 0x44, + NEL = 0x45, + SSA = 0x46, + ESA = 0x47, + HTS = 0x48, + HTJ = 0x49, + VTS = 0x4a, + PLD = 0x4b, + PLU = 0x4c, + RI = 0x4d, + SS2 = 0x4e, + SS3 = 0x4f, + DCS = 0x50, + PU1 = 0x51, + PU2 = 0x52, + STS = 0x53, + CCH = 0x54, + MW = 0x55, + SPA = 0x56, + EPA = 0x57, + SOS = 0x58, + NOT_DEFINED3 = 0x59, + SCI = 0x5a, + CSI = 0x5b, + ST = 0x5c, + OSC = 0x5d, + PM = 0x5e, + APC = 0x5f, + C1_7bit_Stop = 0x60 +}; +QDebug operator<<(QDebug debug, C1_7bit character); +} +namespace C1_8bit { +enum C1_8bit { + C1_8bit_Start = 0x80, + NOT_DEFINED = C1_8bit_Start, + NOT_DEFINED1 = 0x81, + BPH = 0x82, + NBH = 0x83, + NOT_DEFINED2 = 0x84, + NEL = 0x85, + SSA = 0x86, + ESA = 0x87, + HTS = 0x88, + HTJ = 0x89, + VTS = 0x8a, + PLD = 0x8b, + PLU = 0x8c, + RI = 0x8d, + SS2 = 0x8e, + SS3 = 0x8f, + DCS = 0x90, + PU1 = 0x91, + PU2C1_7bit = 0x92, + STS = 0x93, + CCH = 0x94, + MW = 0x95, + SPA = 0x96, + EPA = 0x97, + SOS = 0x98, + NOT_DEFINED3 = 0x99, + SCI = 0x9a, + CSI = 0x9b, + ST = 0x9c, + OSC = 0x9d, + PM = 0x9e, + APC = 0x9f, + C1_8bit_Stop = 0xa0 +}; +QDebug operator<<(QDebug debug, C1_8bit character); +} + +namespace FinalBytesNoIntermediate { +enum FinalBytesNoIntermediate { + ICH = 0x40, + CUU = 0x41, + CUD = 0x42, + CUF = 0x43, + CUB = 0x44, + CNL = 0x45, + CPL = 0x46, + CHA = 0x47, + CUP = 0x48, + CHT = 0x49, + ED = 0x4a, + EL = 0x4b, + IL = 0x4c, + DL = 0x4d, + EF = 0x4e, + EA = 0x4f, + DCH = 0x50, + SSE = 0x51, + CPR = 0x52, + SU = 0x53, + SD = 0x54, + NP = 0x55, + PP = 0x56, + CTC = 0x57, + ECH = 0x58, + CVT = 0x59, + CBT = 0x5a, + SRS = 0x5b, + PTX = 0x5c, + SDS = 0x5d, + SIMD = 0x5e, + NOT_DEFINED = 0x5f, + HPA = 0x60, + HPR = 0x61, + REP = 0x62, + DA = 0x63, + VPA = 0x64, + VPR = 0x65, + HVP = 0x66, + TBC = 0x67, + SM = 0x68, + MC = 0x69, + HPB = 0x6a, + VPB = 0x6b, + RM = 0x6c, + SGR = 0x6d, + DSR = 0x6e, + DAQ = 0x6f, + Reserved0 = 0x70, + Reserved1 = 0x71, + DECSTBM = 0x72, + Reserved3 = 0x73, + Reserved4 = 0x74, + Reserved5 = 0x75, + Reserved6 = 0x76, + Reserved7 = 0x77, + Reserved8 = 0x78, + Reserved9 = 0x79, + Reserveda = 0x7a, + Reservedb = 0x7b, + Reservedc = 0x7c, + Reservedd = 0x7d, + Reservede = 0x7e, + Reservedf = 0x7f +}; +QDebug operator<<(QDebug debug, FinalBytesNoIntermediate character); +} + +namespace FinalBytesSingleIntermediate { +enum FinalBytesSingleIntermediate { + SL = 0x40, + SR = 0x41, + GSM = 0x42, + GSS = 0x43, + FNT = 0x44, + TSS = 0x45, + JFY = 0x46, + SPI = 0x47, + QUAD = 0x48, + SSU = 0x49, + PFS = 0x4a, + SHS = 0x4b, + SVS = 0x4c, + IGS = 0x4d, + NOT_DEFINED = 0x4e, + IDCS = 0x4f, + PPA = 0x50, + PPR = 0x51, + PPB = 0x52, + SPD = 0x53, + DTA = 0x54, + SHL = 0x55, + SLL = 0x56, + FNK = 0x57, + SPQR = 0x58, + SEF = 0x59, + PEC = 0x5a, + SSW = 0x5b, + SACS = 0x5c, + SAPV = 0x5d, + STAB = 0x5e, + GCC = 0x5f, + TATE = 0x60, + TALE = 0x61, + TAC = 0x62, + TCC = 0x63, + TSR = 0x64, + SCO = 0x65, + SRCS = 0x66, + SCS = 0x67, + SLS = 0x68, + NOT_DEFINED2 = 0x69, + NOT_DEFINED3 = 0x6a, + SCP = 0x6b, + NOT_DEFINED4 = 0x6c, + NOT_DEFINED5 = 0x6d, + NOT_DEFINED6 = 0x6e, + NOT_DEFINED7 = 0x6f, + Reserved0 = 0x70, + Reserved1 = 0x71, + Reserved2 = 0x72, + Reserved3 = 0x73, + Reserved4 = 0x74, + Reserved5 = 0x75, + Reserved6 = 0x76, + Reserved7 = 0x77, + Reserved8 = 0x78, + Reserved9 = 0x79, + Reserveda = 0x7a, + Reservedb = 0x7b, + Reservedc = 0x7c, + Reservedd = 0x7d, + Reservedf = 0x7f +}; +QDebug operator<<(QDebug debug, FinalBytesSingleIntermediate character); +} + +#endif // CONTROLL_CHARS_H diff --git a/yat/backend/cursor.cpp b/yat/backend/cursor.cpp new file mode 100644 index 0000000..bd6d4f1 --- /dev/null +++ b/yat/backend/cursor.cpp @@ -0,0 +1,542 @@ +/****************************************************************************** +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#include "cursor.h" + +#include "block.h" +#include "screen_data.h" + +#include + +Cursor::Cursor(Screen* screen) + : QObject(screen) + , m_screen(screen) + , m_current_text_style(screen->defaultTextStyle()) + , m_position(0,0) + , m_new_position(0,0) + , m_document_width(screen->width()) + , m_document_height(screen->height()) + , m_top_margin(0) + , m_bottom_margin(0) + , m_scroll_margins_set(false) + , m_origin_at_margin(false) + , m_notified(false) + , m_visible(true) + , m_new_visibillity(true) + , m_blinking(false) + , m_new_blinking(false) + , m_wrap_around(true) + , m_content_height_changed(false) + , m_insert_mode(Replace) +{ + connect(screen, SIGNAL(widthAboutToChange(int)), this, SLOT(setDocumentWidth(int))); + connect(screen, SIGNAL(heightAboutToChange(int, int, int)), this, SLOT(setDocumentHeight(int, int, int))); + connect(screen, SIGNAL(contentHeightChanged()), this, SLOT(contentHeightChanged())); + + m_gl_text_codec = QTextCodec::codecForName("utf-8")->makeDecoder(); + m_gr_text_codec = QTextCodec::codecForName("utf-8")->makeDecoder(); + + for (int i = 0; i < m_document_width; i++) { + if (i % 8 == 0) { + m_tab_stops.append(i); + } + } +} + +Cursor::~Cursor() +{ + +} + +void Cursor::setDocumentWidth(int width) +{ + if (width > m_document_width) { + for (int i = m_document_width -1; i < width; i++) { + if (i % 8 == 0) { + m_tab_stops.append(i); + } + } + } + + m_document_width = width; + if (new_x() >= width) { + new_rx() = width - 1; + notifyChanged(); + } +} + +void Cursor::setDocumentHeight(int height, int currentCursorBlock, int currentScrollBackHeight) +{ + Q_UNUSED(currentCursorBlock); + resetScrollArea(); + if (m_document_height > height) { + const int to_remove = m_document_height - height; + const int removeLinesBelowCursor = + std::min(m_document_height - new_y(), to_remove); + const int removeLinesAtTop = to_remove - removeLinesBelowCursor; + if (!removeLinesAtTop) { + new_ry() -= removeLinesAtTop; + notifyChanged(); + + } + } else { + int height_diff = height - m_document_height; + if (currentScrollBackHeight >= height_diff) { + new_ry() += height_diff; + } else if (currentScrollBackHeight > 0) { + const int move = height_diff - currentScrollBackHeight; + new_ry() += move; + } + } + + m_document_height = height; + + if (new_y() >= height) { + new_ry() = height - 1; + notifyChanged(); + } + if (new_y() <= 0) { + new_ry() = 0; + } +} + +bool Cursor::visible() const +{ + return m_visible; +} +void Cursor::setVisible(bool visible) +{ + m_new_visibillity = visible; +} + +bool Cursor::blinking() const +{ + return m_blinking; +} + +void Cursor::setBlinking(bool blinking) +{ + m_new_blinking = blinking; +} + +void Cursor::setTextStyle(TextStyle::Style style, bool add) +{ + if (add) { + m_current_text_style.style |= style; + } else { + m_current_text_style.style &= !style; + } +} + +void Cursor::resetStyle() +{ + m_current_text_style.background = ColorPalette::DefaultBackground; + m_current_text_style.forground = ColorPalette::DefaultForground; + m_current_text_style.style = TextStyle::Normal; +} + +void Cursor::scrollUp(int lines) +{ + if (new_y() < top() || new_y() > bottom()) + return; + for (int i = 0; i < lines; i++) { + screen_data()->moveLine(bottom(), top()); + } +} + +void Cursor::scrollDown(int lines) +{ + if (new_y() < top() || new_y() > bottom()) + return; + for (int i = 0; i < lines; i++) { + screen_data()->moveLine(top(), bottom()); + } +} + +void Cursor::setTextCodec(QTextCodec *codec) +{ + m_gl_text_codec = codec->makeDecoder(); +} + +void Cursor::setInsertMode(InsertMode mode) +{ + m_insert_mode = mode; +} + +TextStyle Cursor::currentTextStyle() const +{ + return m_current_text_style; +} + +void Cursor::setTextStyleColor(ushort color) +{ + Q_ASSERT(color >= 30 && color < 50); + if (color < 38) { + m_current_text_style.forground = ColorPalette::Color(color - 30); + } else if (color == 39) { + m_current_text_style.forground = ColorPalette::DefaultForground; + } else if (color >= 40 && color < 48) { + m_current_text_style.background = ColorPalette::Color(color - 40); + } else if (color == 49) { + m_current_text_style.background = ColorPalette::DefaultBackground; + } else { + qDebug() << "Failed to set color"; + } +} + +ColorPalette *Cursor::colorPalette() const +{ + return m_screen->colorPalette(); +} + +QPoint Cursor::position() const +{ + return m_position; +} + +int Cursor::x() const +{ + return m_position.x(); +} + +int Cursor::y() const +{ + return (m_screen->currentScreenData()->contentHeight() - m_screen->height()) + m_position.y(); +} + +void Cursor::moveOrigin() +{ + m_new_position = QPoint(0,adjusted_top()); + notifyChanged(); +} + +void Cursor::moveBeginningOfLine() +{ + new_rx() = 0; + notifyChanged(); +} + +void Cursor::moveUp(int lines) +{ + int adjusted_new_y = this->adjusted_new_y(); + if (!adjusted_new_y || !lines) + return; + + if (lines < adjusted_new_y) { + new_ry() -= lines; + } else { + new_ry() = adjusted_top(); + } + notifyChanged(); +} + +void Cursor::moveDown(int lines) +{ + int bottom = adjusted_bottom(); + if (new_y() == bottom || !lines) + return; + + if (new_y() + lines <= bottom) { + new_ry() += lines; + } else { + new_ry() = bottom; + } + notifyChanged(); +} + +void Cursor::moveLeft(int positions) +{ + if (!new_x() || !positions) + return; + if (positions < new_x()) { + new_rx() -= positions; + } else { + new_rx() = 0; + } + notifyChanged(); +} + +void Cursor::moveRight(int positions) +{ + int width = m_screen->width(); + if (new_x() == width -1 || !positions) + return; + if (positions < width - new_x()) { + new_rx() += positions; + } else { + new_rx() = width -1; + } + + notifyChanged(); +} + +void Cursor::move(int new_x, int new_y) +{ + int width = m_screen->width(); + + if (m_origin_at_margin) { + new_y += m_top_margin; + } + + if (new_x < 0) { + new_x = 0; + } else if (new_x >= width) { + new_x = width - 1; + } + + if (new_y < adjusted_top()) { + new_y = adjusted_top(); + } else if (new_y > adjusted_bottom()) { + new_y = adjusted_bottom(); + } + + if (this->new_y() != new_y || this->new_x() != new_x) { + m_new_position = QPoint(new_x, new_y); + notifyChanged(); + } +} + +void Cursor::moveToLine(int line) +{ + const int height = m_screen->height(); + if (line < adjusted_top()) { + line = 0; + } else if (line > adjusted_bottom()) { + line = height -1; + } + + if (line != new_y()) { + new_rx() = line; + notifyChanged(); + } +} + +void Cursor::moveToCharacter(int character) +{ + const int width = m_screen->width(); + if (character < 0) { + character = 1; + } else if (character > width) { + character = width; + } + if (character != new_x()) { + new_rx() = character; + notifyChanged(); + } +} + +void Cursor::moveToNextTab() +{ + for (int i = 0; i < m_tab_stops.size(); i++) { + if (new_x() < m_tab_stops.at(i)) { + moveToCharacter(std::min(m_tab_stops.at(i), m_document_width -1)); + return; + } + } + moveToCharacter(m_document_width - 1); +} + +void Cursor::setTabStop() +{ + int i; + for (i = 0; i < m_tab_stops.size(); i++) { + if (new_x() == m_tab_stops.at(i)) + return; + if (new_x() > m_tab_stops.at(i)) { + continue; + } else { + break; + } + } + m_tab_stops.insert(i,new_x()); +} + +void Cursor::removeTabStop() +{ + for (int i = 0; i < m_tab_stops.size(); i++) { + if (new_x() == m_tab_stops.at(i)) { + m_tab_stops.remove(i); + return; + } else if (new_x() < m_tab_stops.at(i)) { + return; + } + } +} + +void Cursor::clearTabStops() +{ + m_tab_stops.clear(); +} + +void Cursor::clearToBeginningOfLine() +{ + screen_data()->clearToBeginningOfLine(m_new_position); +} + +void Cursor::clearToEndOfLine() +{ + screen_data()->clearToEndOfLine(m_new_position); +} + +void Cursor::clearToBeginningOfScreen() +{ + clearToBeginningOfLine(); + if (new_y() > 0) + screen_data()->clearToBeginningOfScreen(m_new_position.y()-1); +} + +void Cursor::clearToEndOfScreen() +{ + clearToEndOfLine(); + if (new_y() < m_screen->height() -1) { + screen_data()->clearToEndOfScreen(m_new_position.y()+1); + } +} + +void Cursor::clearLine() +{ + screen_data()->clearLine(m_new_position); +} + +void Cursor::deleteCharacters(int characters) +{ + screen_data()->deleteCharacters(m_new_position, new_x() + characters -1); +} + +void Cursor::setWrapAround(bool wrap) +{ + m_wrap_around = wrap; +} + +void Cursor::addAtCursor(const QByteArray &data, bool only_latin) +{ + if (m_insert_mode == Replace) { + replaceAtCursor(data, only_latin); + } else { + insertAtCursor(data, only_latin); + } +} + +void Cursor::replaceAtCursor(const QByteArray &data, bool only_latin) +{ + const QString text = m_gl_text_codec->toUnicode(data); + + if (!m_wrap_around && new_x() + text.size() > m_screen->width()) { + const int size = m_document_width - new_x(); + QString toBlock = text.mid(0,size); + toBlock.replace(toBlock.size() - 1, 1, text.at(text.size()-1)); + screen_data()->replace(m_new_position, toBlock, m_current_text_style, only_latin); + new_rx() += toBlock.size(); + } else { + auto diff = screen_data()->replace(m_new_position, text, m_current_text_style, only_latin); + new_rx() += diff.character; + new_ry() += diff.line; + } + + if (new_y() >= m_document_height) + new_ry() = m_document_height - 1; + + notifyChanged(); +} + +void Cursor::insertAtCursor(const QByteArray &data, bool only_latin) +{ + const QString text = m_gl_text_codec->toUnicode(data); + auto diff = screen_data()->insert(m_new_position, text, m_current_text_style, only_latin); + new_rx() += diff.character; + new_ry() += diff.line; + if (new_y() >= m_document_height) + new_ry() = m_document_height - 1; + if (new_x() >= m_document_width) + new_rx() = m_document_width - 1; +} + +void Cursor::lineFeed() +{ + if(new_y() >= bottom()) { + screen_data()->insertLine(bottom(), top()); + } else { + new_ry()++; + notifyChanged(); + } +} + +void Cursor::reverseLineFeed() +{ + if (new_y() == top()) { + scrollUp(1); + } else { + new_ry()--; + notifyChanged(); + } +} + +void Cursor::setOriginAtMargin(bool atMargin) +{ + m_origin_at_margin = atMargin; + m_new_position = QPoint(0, adjusted_top()); + notifyChanged(); +} + +void Cursor::setScrollArea(int from, int to) +{ + m_top_margin = from; + m_bottom_margin = std::min(to,m_document_height -1); + m_scroll_margins_set = true; +} + +void Cursor::resetScrollArea() +{ + m_top_margin = 0; + m_bottom_margin = 0; + m_scroll_margins_set = false; +} + +void Cursor::dispatchEvents() +{ + if (m_new_position != m_position|| m_content_height_changed) { + bool emit_x_changed = m_new_position.x() != m_position.x(); + bool emit_y_changed = m_new_position.y() != m_position.y(); + m_position = m_new_position; + if (emit_x_changed) + emit xChanged(); + if (emit_y_changed || m_content_height_changed) + emit yChanged(); + } + + if (m_new_visibillity != m_visible) { + m_visible = m_new_visibillity; + emit visibilityChanged(); + } + + if (m_new_blinking != m_blinking) { + m_blinking = m_new_blinking; + emit blinkingChanged(); + } +} + +void Cursor::contentHeightChanged() +{ + m_content_height_changed = true; +} + diff --git a/yat/backend/cursor.h b/yat/backend/cursor.h new file mode 100644 index 0000000..95723fc --- /dev/null +++ b/yat/backend/cursor.h @@ -0,0 +1,175 @@ +/****************************************************************************** +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#ifndef CURSOR_H +#define CURSOR_H + +#include "text_style.h" +#include "screen.h" + +#include + +class Cursor : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibilityChanged) + Q_PROPERTY(bool blinking READ blinking WRITE setBlinking NOTIFY blinkingChanged) + Q_PROPERTY(int x READ x NOTIFY xChanged) + Q_PROPERTY(int y READ y NOTIFY yChanged) +public: + enum InsertMode { + Insert, + Replace + }; + + Cursor(Screen *screen); + ~Cursor(); + + bool visible() const; + void setVisible(bool visible); + + bool blinking() const; + void setBlinking(bool blinking); + + void setTextStyle(TextStyle::Style style, bool add = true); + void resetStyle(); + TextStyle currentTextStyle() const; + + void setTextStyleColor(ushort color); + ColorPalette *colorPalette() const; + + QPoint position() const; + int x() const; + int y() const; + int new_x() const { return m_new_position.x(); } + int new_y() const { return m_new_position.y(); } + + void moveOrigin(); + void moveBeginningOfLine(); + void moveUp(int lines = 1); + void moveDown(int lines = 1); + void moveLeft(int positions = 1); + void moveRight(int positions = 1); + void move(int new_x, int new_y); + void moveToLine(int line); + void moveToCharacter(int character); + + void moveToNextTab(); + void setTabStop(); + void removeTabStop(); + void clearTabStops(); + + void clearToBeginningOfLine(); + void clearToEndOfLine(); + void clearToBeginningOfScreen(); + void clearToEndOfScreen(); + void clearLine(); + + void deleteCharacters(int characters); + + void setWrapAround(bool wrap); + void addAtCursor(const QByteArray &text, bool only_latin = true); + void insertAtCursor(const QByteArray &text, bool only_latin = true); + void replaceAtCursor(const QByteArray &text, bool only_latin = true); + + void lineFeed(); + void reverseLineFeed(); + + void setOriginAtMargin(bool atMargin); + void setScrollArea(int from, int to); + void resetScrollArea(); + + void scrollUp(int lines); + void scrollDown(int lines); + + void setTextCodec(QTextCodec *codec); + + void setInsertMode(InsertMode mode); + + inline void notifyChanged(); + void dispatchEvents(); + +public slots: + void setDocumentWidth(int width); + void setDocumentHeight(int height, int currentCursorBlock, int currentScrollBackHeight); + +signals: + void xChanged(); + void yChanged(); + void visibilityChanged(); + void blinkingChanged(); + +private slots: + void contentHeightChanged(); + +private: + ScreenData *screen_data() const { return m_screen->currentScreenData(); } + int &new_rx() { return m_new_position.rx(); } + int &new_ry() { return m_new_position.ry(); } + int adjusted_new_x() const { return m_origin_at_margin ? + m_new_position.x() - m_top_margin : m_new_position.x(); } + int adjusted_new_y() const { return m_origin_at_margin ? + m_new_position.y() - m_top_margin : m_new_position.y(); } + int adjusted_top() const { return m_origin_at_margin ? m_top_margin : 0; } + int adjusted_bottom() const { return m_origin_at_margin ? m_bottom_margin : m_document_height - 1; } + int top() const { return m_scroll_margins_set ? m_top_margin : 0; } + int bottom() const { return m_scroll_margins_set ? m_bottom_margin : m_document_height - 1; } + Screen *m_screen; + TextStyle m_current_text_style; + QPoint m_position; + QPoint m_new_position; + + int m_document_width; + int m_document_height; + + int m_top_margin; + int m_bottom_margin; + bool m_scroll_margins_set; + bool m_origin_at_margin; + + QVector m_tab_stops; + + bool m_notified; + bool m_visible; + bool m_new_visibillity; + bool m_blinking; + bool m_new_blinking; + bool m_wrap_around; + bool m_content_height_changed; + + QTextDecoder *m_gl_text_codec; + QTextDecoder *m_gr_text_codec; + + InsertMode m_insert_mode; +}; + +void Cursor::notifyChanged() +{ + if (!m_notified) { + m_notified = true; + m_screen->scheduleEventDispatch(); + } +} + +#endif //CUROSOR_H diff --git a/yat/backend/main.cpp b/yat/backend/main.cpp new file mode 100644 index 0000000..1b09d79 --- /dev/null +++ b/yat/backend/main.cpp @@ -0,0 +1,32 @@ +/************************************************************************************************** +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +* associated documentation files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, publish, distribute, +* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +* OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +***************************************************************************************************/ + +#include "terminal_state.h" + +#include + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + TerminalState state; + + return app.exec(); +} diff --git a/yat/backend/nrc_text_codec.cpp b/yat/backend/nrc_text_codec.cpp new file mode 100644 index 0000000..26f3e93 --- /dev/null +++ b/yat/backend/nrc_text_codec.cpp @@ -0,0 +1,124 @@ +/****************************************************************************** +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#include "nrc_text_codec.h" + +static bool nrc_text_codec_init = false; +void NrcTextCodec::initialize() +{ + if (!nrc_text_codec_init) { + nrc_text_codec_init = true; + new NrcTextCodec("dec_special_graphics", 500001, dec_special_graphics_char_set); + new NrcTextCodec("nrc_british", 500002, nrc_british_char_set); + new NrcTextCodec("nrc_norwegian_danish", 5002, nrc_norwegian_danish_char_set); + new NrcTextCodec("nrc_dutch", 5002, nrc_dutch_char_set); + new NrcTextCodec("nrc_finnish", 5002, nrc_finnish_char_set); + new NrcTextCodec("nrc_french", 5002, nrc_french_char_set); + new NrcTextCodec("nrc_french_canadian", 5002, nrc_french_canadian_char_set); + new NrcTextCodec("nrc_german", 5002, nrc_german_char_set); + new NrcTextCodec("nrc_italian", 5002, nrc_italian_char_set); + new NrcTextCodec("nrc_spanish", 5002, nrc_spanish_char_set); + new NrcTextCodec("nrc_swedish", 5002, nrc_swedish_char_set); + new NrcTextCodec("nrc_swiss", 5002, nrc_swiss_char_set); + } +} + +NrcTextCodec::NrcTextCodec(const QByteArray &name, int mib, const QChar character_set[]) + : QTextCodec() + , m_name(name) + , m_mib(mib) + , m_character_set(character_set) +{ +} + +QByteArray NrcTextCodec::name() const +{ + return m_name; +} +int NrcTextCodec::mibEnum() const +{ + return m_mib; +} + +QString NrcTextCodec::convertToUnicode(const char *in, int length, QTextCodec::ConverterState *state) const +{ + QString ret_str; + ret_str.reserve(length); + for (int i = 0; i < length; i++) { + uchar in_char = *(in + i); + if (in_char < 128) { + QChar unicode = m_character_set[in_char]; + if (unicode.isNull()) + unicode = QChar(in_char); + ret_str.append(unicode); + } else { + if (state) { + if (state->flags & QTextCodec::ConvertInvalidToNull) { + state->invalidChars++; + ret_str.append(0); + } else { + state->invalidChars++; + state->remainingChars = length - i; + return ret_str; + } + } + } + } + return ret_str; +} + +QByteArray NrcTextCodec::convertFromUnicode(const QChar *in, int length, ConverterState *state) const +{ + QByteArray ret_array; + ret_array.reserve(length); + + for (int i = 0; i < length; i++) { + QChar out_char = *(in + i); + if (out_char.unicode() < 128) { + uchar out = out_char.unicode(); + ret_array.append(out); + } else { + bool found = false; + for (uchar n = 0; n < 128; n++) { + if (m_character_set[n] == out_char) { + ret_array.append(n); + found = true; + break; + } + } + + if (!found && state) { + if (state->flags & QTextCodec::ConvertInvalidToNull) { + state->invalidChars++; + ret_array.append(char(0)); + } else { + state->invalidChars++; + state->remainingChars = length - i; + return ret_array; + } + } + } + } + return ret_array; +} + diff --git a/yat/backend/nrc_text_codec.h b/yat/backend/nrc_text_codec.h new file mode 100644 index 0000000..5d5eb13 --- /dev/null +++ b/yat/backend/nrc_text_codec.h @@ -0,0 +1,45 @@ +/****************************************************************************** +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#include "character_sets.h" + +#include +#include + +class NrcTextCodec : public QTextCodec +{ +public: + NrcTextCodec(const QByteArray &name, int mib, const QChar character_set[]); + QByteArray name() const; + int mibEnum() const; + + static void initialize(); +protected: + QString convertToUnicode(const char *in, int length, ConverterState *state) const; + QByteArray convertFromUnicode(const QChar *in, int length, ConverterState *state) const; + +private: + const QByteArray m_name; + const int m_mib; + const QChar *m_character_set; +}; diff --git a/yat/backend/parser.cpp b/yat/backend/parser.cpp new file mode 100644 index 0000000..fb5c286 --- /dev/null +++ b/yat/backend/parser.cpp @@ -0,0 +1,1329 @@ +/******************************************************************************* +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#include "parser.h" + +#include "controll_chars.h" +#include "screen.h" +#include "cursor.h" +#include "nrc_text_codec.h" + +#include +#include + + +static bool yat_parser_debug = qEnvironmentVariableIsSet("YAT_PARSER_DEBUG"); + +namespace CharacterSet { +enum CharacterSet { + utf_8, + ascii, + latin_1, + dec_special_graphics, + nrc_british, + nrc_norwegian_danish, + nrc_dutch, + nrc_finnish, + nrc_french, + nrc_french_canadian, + nrc_german, + nrc_italian, + nrc_spanish, + nrc_swedish, + nrc_swiss +}; +} + +QTextCodec *codecForCharacterset(CharacterSet::CharacterSet characterSet) { + QTextCodec *codec = 0; + switch(characterSet) { + case CharacterSet::utf_8: + codec = QTextCodec::codecForName("utf-8"); + break; + case CharacterSet::ascii: + codec = QTextCodec::codecForName("utf-8"); + break; + case CharacterSet::latin_1: + codec = QTextCodec::codecForName("latin-1"); + break; + case CharacterSet::dec_special_graphics: + codec = QTextCodec::codecForName("dec_special_graphics"); + break; + case CharacterSet::nrc_british: + codec = QTextCodec::codecForName("nrc_british"); + break; + case CharacterSet::nrc_norwegian_danish: + codec = QTextCodec::codecForName("nrc_norwegian_danish"); + break; + case CharacterSet::nrc_dutch: + codec = QTextCodec::codecForName("nrc_dutch"); + break; + case CharacterSet::nrc_finnish: + codec = QTextCodec::codecForName("nrc_finnish"); + break; + case CharacterSet::nrc_french: + codec = QTextCodec::codecForName("nrc_french"); + break; + case CharacterSet::nrc_french_canadian: + codec = QTextCodec::codecForName("nrc_french_canadian"); + break; + case CharacterSet::nrc_german: + codec = QTextCodec::codecForName("nrc_german"); + break; + case CharacterSet::nrc_italian: + codec = QTextCodec::codecForName("nrc_italian"); + break; + case CharacterSet::nrc_spanish: + codec = QTextCodec::codecForName("nrc_spanish"); + break; + case CharacterSet::nrc_swedish: + codec = QTextCodec::codecForName("nrc_swedish"); + break; + case CharacterSet::nrc_swiss: + codec = QTextCodec::codecForName("nrc_swiss"); + break; + } + if (!codec) { + qDebug() << "Failed to find codec for" << characterSet << ". Returning utf-8"; + return QTextCodec::codecForName("utf-8"); + } + return codec; +} + + +static const QByteArray getByteArrayMidNoCopy(const QByteArray &array, int start, int length) +{ + length = std::min(length, array.size() - start); + + if (start >= array.size() || length < 1) + return QByteArray(); + + const char *data_at_start = array.data() + start; + return QByteArray::fromRawData(data_at_start, length); +} +static void printParameters(const QVector ¶meters, QDebug &debug, bool dec_private = false) +{ + if (dec_private) + debug << "?"; + for (int i = 0; i < parameters.size(); i++) { + if (i == 0) + debug << " "; + else + debug << ";"; + debug << parameters.at(i); + } +} + +Parser::Parser(Screen *screen) + : m_decode_state(PlainText) + , m_current_token_start(0) + , m_current_position(0) + , m_intermediate_char(QChar()) + , m_parameters(10) + , m_parameters_expecting_more(false) + , m_dec_mode(false) + , m_gt_param(false) + , m_lnm_mode_set(false) + , m_contains_only_latin(true) + , m_screen(screen) +{ + for (uint i = 0; i < sizeof(m_graphic_codecs) / sizeof *m_graphic_codecs; i++) { + m_graphic_codecs[i] = QTextCodec::codecForName("utf-8"); + } + + NrcTextCodec::initialize(); +} + +void Parser::addData(const QByteArray &data) +{ + m_current_token_start = 0; + m_current_data = data; + + for (m_current_position = 0; m_current_position < m_current_data.size(); m_current_position++) { + uchar character = m_current_data.at(m_current_position); + if (character > 127) + m_utf8_decoder.addChar(character); + switch (m_decode_state) { + case PlainText: + if (character < C0::C0_END || m_utf8_decoder.isC1()) { + if (m_current_position != m_current_token_start) { + const QByteArray to_insert = getByteArrayMidNoCopy(m_current_data, m_current_token_start, m_current_position - m_current_token_start); + if (yat_parser_debug) + qDebug() << "Parser Insert text:" << to_insert; + m_screen->currentCursor()->addAtCursor(to_insert, m_contains_only_latin); + tokenFinished(); + m_current_token_start--; + } + m_decode_state = DecodeC0; + decodeC0(m_current_data.at(m_current_position)); + } + m_contains_only_latin = m_contains_only_latin && m_utf8_decoder.isLatin(); + break; + case DecodeC0: + decodeC0(character); + break; + case DecodeC1_7bit: + decodeC1_7bit(character); + break; + case DecodeCSI: + decodeCSI(character); + break; + case DecodeOSC: + decodeOSC(character); + break; + case DecodeCharacterSet: + decodeCharacterSet(character); + break; + case DecodeFontSize: + decodeFontSize(character); + break; + } + + } + if (m_decode_state == PlainText) { + QByteArray to_insert = getByteArrayMidNoCopy(m_current_data, m_current_token_start, m_current_data.size() - m_current_token_start); + if (to_insert.size()) { + if (yat_parser_debug) + qDebug() << "Parser Insert text:" << to_insert; + m_screen->currentCursor()->addAtCursor(to_insert, m_contains_only_latin); + tokenFinished(); + } + } + m_current_data = QByteArray(); +} + +void Parser::decodeC0(uchar character) +{ + if (yat_parser_debug) { + qDebug() << C0::C0(character); + } + switch (character) { + case C0::NUL: + case C0::SOH: + case C0::STX: + case C0::ETX: + case C0::EOT: + case C0::ENQ: + case C0::ACK: + qDebug() << "Unhandled" << C0::C0(character); + if (m_decode_state == DecodeC0) + tokenFinished(); + break; + case C0::BEL: + m_screen->scheduleFlash(); + if (m_decode_state == DecodeC0) + tokenFinished(); + break; + case C0::BS: + m_screen->currentCursor()->moveLeft(); + if (m_decode_state == DecodeC0) + tokenFinished(); + break; + case C0::HT: + m_screen->currentCursor()->moveToNextTab(); + if (m_decode_state == DecodeC0) + tokenFinished(); + break; + case C0::LF: + case C0::VT: + case C0::FF: + if (m_lnm_mode_set) + m_screen->currentCursor()->moveBeginningOfLine(); + m_screen->currentCursor()->lineFeed(); + if (m_decode_state == DecodeC0) + tokenFinished(); + break; + case C0::CR: + m_screen->currentCursor()->moveBeginningOfLine(); + if (m_decode_state == DecodeC0) + tokenFinished(); + break; + case C0::SOorLS1: + m_screen->currentCursor()->setTextCodec(m_graphic_codecs[1]); + if (m_decode_state == DecodeC0) + tokenFinished(); + break; + case C0::SIorLS0: + m_screen->currentCursor()->setTextCodec(m_graphic_codecs[0]); + if (m_decode_state == DecodeC0) + tokenFinished(); + break; + case C0::DLE: + case C0::DC1: + case C0::DC2: + case C0::DC3: + case C0::DC4: + case C0::NAK: + case C0::SYN: + case C0::ETB: + case C0::CAN: + case C0::EM: + case C0::SUB: + qDebug() << "Unhandled" << C0::C0(character); + if (m_decode_state == DecodeC0) + tokenFinished(); + break; + case C0::ESC: + if (m_decode_state != DecodeC0) { + tokenFinished(); + break; + } + m_decode_state = DecodeC1_7bit; + break; + if (m_decode_state != DecodeC0) + tokenFinished(); + break; + case C0::IS4: + case C0::IS3: + case C0::IS2: + case C0::IS1: + default: + qDebug() << "Unhandled" << C0::C0(character); + if (m_decode_state == DecodeC0) + tokenFinished(); + break; + } +} + +void Parser::decodeC1_7bit(uchar character) +{ + if (yat_parser_debug) { + qDebug() << C1_7bit::C1_7bit(character); + } + switch(character) { + case C1_7bit::ESC: + tokenFinished(); + break; + case '#': + m_decode_state = DecodeFontSize; + break; + case C1_7bit::SCS_G0: + m_decode_state = DecodeCharacterSet; + m_decode_graphics_set = 0; + break; + case C1_7bit::SCS_G1: + m_decode_state = DecodeCharacterSet; + m_decode_graphics_set = 1; + break; + case C1_7bit::SCS_G2: + m_decode_state = DecodeCharacterSet; + m_decode_graphics_set = 2; + break; + case C1_7bit::SCS_G3: + m_decode_state = DecodeCharacterSet; + m_decode_graphics_set = 3; + break; + case C1_7bit::DECSC: + m_screen->saveCursor(); + tokenFinished(); + break; + case C1_7bit::DECRC: + m_screen->restoreCursor(); + tokenFinished(); + break; + case '=': + qDebug() << "Application keypad"; + tokenFinished(); + break; + case '>': + qDebug() << "Normal keypad mode"; + tokenFinished(); + break; + case C1_7bit::NOT_DEFINED: + case C1_7bit::NOT_DEFINED1: + case C1_7bit::BPH: + case C1_7bit::NBH: + qDebug() << "Unhandled" << C1_7bit::C1_7bit(character); + tokenFinished(); + break; + case C1_7bit::IND: + m_screen->currentCursor()->moveDown(); + tokenFinished(); + break; + case C1_7bit::NEL: + m_screen->currentCursor()->moveBeginningOfLine(); + m_screen->currentCursor()->lineFeed(); + tokenFinished(); + break; + case C1_7bit::SSA: + case C1_7bit::ESA: + qDebug() << "Unhandled" << C1_7bit::C1_7bit(character); + tokenFinished(); + break; + case C1_7bit::HTS: + m_screen->currentCursor()->setTabStop(); + tokenFinished(); + break; + case C1_7bit::HTJ: + case C1_7bit::VTS: + case C1_7bit::PLD: + case C1_7bit::PLU: + qDebug() << "Unhandled" << C1_7bit::C1_7bit(character); + tokenFinished(); + break; + case C1_7bit::RI: + m_screen->currentCursor()->reverseLineFeed(); + tokenFinished(); + break; + case C1_7bit::SS2: + case C1_7bit::SS3: + case C1_7bit::DCS: + case C1_7bit::PU1: + case C1_7bit::PU2: + case C1_7bit::STS: + case C1_7bit::CCH: + case C1_7bit::MW : + case C1_7bit::SPA: + case C1_7bit::EPA: + case C1_7bit::SOS: + case C1_7bit::NOT_DEFINED3: + case C1_7bit::SCI: + qDebug() << "Unhandled" << C1_7bit::C1_7bit(character); + tokenFinished(); + break; + case C1_7bit::CSI: + m_decode_state = DecodeCSI; + break; + case C1_7bit::ST : + qDebug() << "Unhandled" << C1_7bit::C1_7bit(character); + tokenFinished(); + break; + case C1_7bit::OSC: + m_decode_state = DecodeOSC; + break; + case C1_7bit::PM : + case C1_7bit::APC: + default: + qDebug() << "Unhandled" << C1_7bit::C1_7bit(character); + tokenFinished(); + break; + } +} + +void Parser::decodeParameters(uchar character) +{ + switch (character) { + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + case 0x36: + case 0x37: + case 0x38: + case 0x39: + m_parameter_string.append(character); + break; + case 0x3a: + qDebug() << "Encountered special delimiter in parameterbyte"; + break; + case 0x3b: + if (!m_parameter_string.size()) { + m_parameters.append(INT_MIN); + } else { + appendParameter(); + } + m_parameters_expecting_more = true; + break; + case 0x3c: + case 0x3d: + appendParameter(); + qDebug() << "Parameter decoding INVALID RANGE" << char(character); + m_parameters.append(-character); + break; + case 0x3e: + if (m_parameters.size() == 0 && m_parameter_string.size() == 0) { + m_gt_param = true; + } else { + appendParameter(); + qDebug() << "unknown parameter state"; + } + break; + case 0x3f: + if (m_parameters.size() == 0 && m_parameter_string.size() == 0) { + m_dec_mode = true; + } else { + appendParameter(); + qDebug() << "unknown parameter state"; + } + break; + default: + //this is undefined for now + qDebug() << "Encountered undefined parameter byte"; + break; + } +} + +void Parser::decodeCSI(uchar character) +{ + if (character < C0::C0_END) { + decodeC0(character); + return; + } + + if (character >= 0x30 && character <= 0x3f) { + decodeParameters(character); + } else { + appendParameter(); + if (character >= 0x20 && character <= 0x2f) { + if (m_intermediate_char.unicode()) + qDebug() << "Warning!: double intermediate bytes found in CSI"; + m_intermediate_char = character; + } else if (character >= 0x40 && character <= 0x7d) { + if (m_intermediate_char.unicode()) { + if (yat_parser_debug) { + QDebug debug = qDebug(); + debug << FinalBytesSingleIntermediate::FinalBytesSingleIntermediate(character); + printParameters(m_parameters, debug, m_dec_mode); + } + switch (character) { + case FinalBytesSingleIntermediate::SL: + case FinalBytesSingleIntermediate::SR: + case FinalBytesSingleIntermediate::GSM: + case FinalBytesSingleIntermediate::GSS: + case FinalBytesSingleIntermediate::FNT: + case FinalBytesSingleIntermediate::TSS: + case FinalBytesSingleIntermediate::JFY: + case FinalBytesSingleIntermediate::SPI: + case FinalBytesSingleIntermediate::QUAD: + case FinalBytesSingleIntermediate::SSU: + case FinalBytesSingleIntermediate::PFS: + case FinalBytesSingleIntermediate::SHS: + case FinalBytesSingleIntermediate::SVS: + case FinalBytesSingleIntermediate::IGS: + case FinalBytesSingleIntermediate::IDCS: + case FinalBytesSingleIntermediate::PPA: + case FinalBytesSingleIntermediate::PPR: + case FinalBytesSingleIntermediate::PPB: + case FinalBytesSingleIntermediate::SPD: + case FinalBytesSingleIntermediate::DTA: + case FinalBytesSingleIntermediate::SHL: + case FinalBytesSingleIntermediate::SLL: + case FinalBytesSingleIntermediate::FNK: + case FinalBytesSingleIntermediate::SPQR: + case FinalBytesSingleIntermediate::SEF: + case FinalBytesSingleIntermediate::PEC: + case FinalBytesSingleIntermediate::SSW: + case FinalBytesSingleIntermediate::SACS: + case FinalBytesSingleIntermediate::SAPV: + case FinalBytesSingleIntermediate::STAB: + case FinalBytesSingleIntermediate::GCC: + case FinalBytesSingleIntermediate::TATE: + case FinalBytesSingleIntermediate::TALE: + case FinalBytesSingleIntermediate::TAC: + case FinalBytesSingleIntermediate::TCC: + case FinalBytesSingleIntermediate::TSR: + case FinalBytesSingleIntermediate::SCO: + case FinalBytesSingleIntermediate::SRCS: + case FinalBytesSingleIntermediate::SCS: + case FinalBytesSingleIntermediate::SLS: + case FinalBytesSingleIntermediate::SCP: + default: + qDebug() << "unhandled CSI" << FinalBytesSingleIntermediate::FinalBytesSingleIntermediate(character); + break; + } + tokenFinished(); + } else { + if (yat_parser_debug) { + QDebug debug = qDebug(); + debug << FinalBytesNoIntermediate::FinalBytesNoIntermediate(character); + printParameters(m_parameters, debug, m_dec_mode); + } + switch (character) { + case FinalBytesNoIntermediate::ICH: { + int n_chars = m_parameters.size() ? m_parameters.at(0) : 1; + QByteArray empty(n_chars, ' '); + m_screen->currentCursor()->insertAtCursor(empty); + } + break; + case FinalBytesNoIntermediate::CUU: { + Q_ASSERT(m_parameters.size() < 2); + int move_up = m_parameters.size() ? m_parameters.at(0) : 1; + m_screen->currentCursor()->moveUp(move_up ? move_up : 1); + } + break; + case FinalBytesNoIntermediate::CUD: { + int move_down = m_parameters.size() ? m_parameters.at(0) : 1; + m_screen->currentCursor()->moveDown(move_down ? move_down : 1); + } + break; + case FinalBytesNoIntermediate::CUF:{ + Q_ASSERT(m_parameters.size() < 2); + int move_right = m_parameters.size() ? m_parameters.at(0) : 1; + m_screen->currentCursor()->moveRight(move_right ? move_right : 1); + } + break; + case FinalBytesNoIntermediate::CUB: { + Q_ASSERT(m_parameters.size() < 2); + int move_left = m_parameters.size() ? m_parameters.at(0) : 1; + m_screen->currentCursor()->moveLeft(move_left ? move_left : 1); + } + break; + case FinalBytesNoIntermediate::CNL: + case FinalBytesNoIntermediate::CPL: + qDebug() << "unhandled CSI" << FinalBytesNoIntermediate::FinalBytesNoIntermediate(character); + break; + case FinalBytesNoIntermediate::CHA: { + Q_ASSERT(m_parameters.size() < 2); + handleDefaultParameters(1); + int move_to_pos_on_line = m_parameters.size() ? m_parameters.at(0) : 1; + m_screen->currentCursor()->moveToCharacter(move_to_pos_on_line - 1); + } + break; + case FinalBytesNoIntermediate::CUP: + handleDefaultParameters(1); + if (!m_parameters.size()) { + m_screen->currentCursor()->moveOrigin(); + } else if (m_parameters.size() == 2){ + m_screen->currentCursor()->move(m_parameters.at(1) - 1, m_parameters.at(0) - 1); + } else if (m_parameters.size() == 1){ + m_screen->currentCursor()->move(m_parameters.at(0) - 1, 0); + } + break; + case FinalBytesNoIntermediate::CHT: + qDebug() << "unhandled CSI" << FinalBytesNoIntermediate::FinalBytesNoIntermediate(character); + break; + case FinalBytesNoIntermediate::ED: + if (!m_parameters.size()) { + m_screen->currentCursor()->clearToEndOfScreen(); + } else { + int param = m_parameters.size() ? m_parameters.at(0) : 0; + switch (param) { + case 0: + m_screen->currentCursor()->clearToEndOfScreen(); + break; + case 1: + m_screen->currentCursor()->clearToBeginningOfScreen(); + break; + case 2: + m_screen->clearScreen(); + break; + default: + qDebug() << "Invalid parameter value for FinalBytesNoIntermediate::ED"; + } + } + + break; + case FinalBytesNoIntermediate::EL: + if (!m_parameters.size() || m_parameters.at(0) == 0) { + m_screen->currentCursor()->clearToEndOfLine(); + } else if (m_parameters.at(0) == 1) { + m_screen->currentCursor()->clearToBeginningOfLine(); + } else if (m_parameters.at(0) == 2) { + m_screen->currentCursor()->clearLine(); + } else{ + qDebug() << "Fault when processing FinalBytesNoIntermediate::EL"; + } + break; + case FinalBytesNoIntermediate::IL: { + int count = 1; + if (m_parameters.size()) { + count = m_parameters.at(0); + } + m_screen->currentCursor()->scrollUp(count); + } + break; + case FinalBytesNoIntermediate::DL: { + int count = 1; + if (m_parameters.size()) { + count = m_parameters.at(0); + } + m_screen->currentCursor()->scrollDown(count); + } + break; + case FinalBytesNoIntermediate::EF: + case FinalBytesNoIntermediate::EA: + qDebug() << "unhandled CSI" << FinalBytesNoIntermediate::FinalBytesNoIntermediate(character); + break; + case FinalBytesNoIntermediate::DCH:{ + Q_ASSERT(m_parameters.size() < 2); + int n_chars = m_parameters.size() ? m_parameters.at(0) : 1; + m_screen->currentCursor()->deleteCharacters(n_chars); + } + break; + case FinalBytesNoIntermediate::SSE: + case FinalBytesNoIntermediate::CPR: + case FinalBytesNoIntermediate::SU: + case FinalBytesNoIntermediate::SD: + case FinalBytesNoIntermediate::NP: + case FinalBytesNoIntermediate::PP: + case FinalBytesNoIntermediate::CTC: + case FinalBytesNoIntermediate::ECH: + case FinalBytesNoIntermediate::CVT: + case FinalBytesNoIntermediate::CBT: + case FinalBytesNoIntermediate::SRS: + case FinalBytesNoIntermediate::PTX: + case FinalBytesNoIntermediate::SDS: + case FinalBytesNoIntermediate::SIMD: + case FinalBytesNoIntermediate::HPA: + case FinalBytesNoIntermediate::HPR: + case FinalBytesNoIntermediate::REP: + qDebug() << "unhandled CSI" << FinalBytesNoIntermediate::FinalBytesNoIntermediate(character); + break; + case FinalBytesNoIntermediate::DA: + if (m_gt_param) { + m_screen->sendSecondaryDA(); + } else { + m_screen->sendPrimaryDA(); + } + break; + case FinalBytesNoIntermediate::VPA: { + Q_ASSERT(m_parameters.size() < 2); + handleDefaultParameters(1); + int move_to_line = m_parameters.size() ? m_parameters.at(0) -1 : 0; + m_screen->currentCursor()->moveToLine(move_to_line); + } + break; + case FinalBytesNoIntermediate::VPR: + qDebug() << "unhandled CSI" << FinalBytesNoIntermediate::FinalBytesNoIntermediate(character); + break; + case FinalBytesNoIntermediate::HVP: { + Q_ASSERT(m_parameters.size() <= 2); + handleDefaultParameters(1); + if (!m_parameters.size()) { + m_screen->currentCursor()->moveOrigin(); + } else if (m_parameters.size() == 2){ + m_screen->currentCursor()->move(m_parameters.at(1) - 1, m_parameters.at(0) - 1); + } else if (m_parameters.size() == 1){ + m_screen->currentCursor()->move(m_parameters.at(0) - 1, 0); + } + break; + } + case FinalBytesNoIntermediate::TBC: + if (!m_parameters.size() || m_parameters.at(0) == 0) { + m_screen->currentCursor()->removeTabStop(); + } else if (m_parameters.at(0) == 3) { + m_screen->currentCursor()->clearTabStops(); + } + break; + case FinalBytesNoIntermediate::SM: + if (!m_parameters.size()) { + qDebug() << FinalBytesNoIntermediate::SM << "called without parameter"; + break; + } + for (int i = 0; i < m_parameters.size(); i++) { + if (m_dec_mode) { + setDecMode(m_parameters.at(i)); + } else { + setMode(m_parameters.at(i)); + } + } + break; + case FinalBytesNoIntermediate::MC: + case FinalBytesNoIntermediate::HPB: + case FinalBytesNoIntermediate::VPB: + qDebug() << "unhandled CSI" << FinalBytesNoIntermediate::FinalBytesNoIntermediate(character); + break; + case FinalBytesNoIntermediate::RM: + if (!m_parameters.size()) { + qDebug() << FinalBytesNoIntermediate::RM << "called without parameter"; + break; + } + for (int i = 0; i < m_parameters.size(); i++) { + if (m_dec_mode) { + resetDecMode(m_parameters.at(i)); + } else { + resetMode(m_parameters.at(i)); + } + } + + break; + case FinalBytesNoIntermediate::SGR: + handleDefaultParameters(0); + if (!m_parameters.size()) + m_parameters << 0; + handleSGR(); + break; + case FinalBytesNoIntermediate::DSR: + qDebug() << "report"; + case FinalBytesNoIntermediate::DAQ: + case FinalBytesNoIntermediate::Reserved0: + case FinalBytesNoIntermediate::Reserved1: + qDebug() << "Unhandeled CSI" << FinalBytesNoIntermediate::FinalBytesNoIntermediate(character); + break; + case FinalBytesNoIntermediate::DECSTBM: + if (m_parameters.size() == 2) { + if (m_parameters.at(0) >= 0) { + m_screen->currentCursor()->setScrollArea(m_parameters.at(0) - 1,m_parameters.at(1) - 1); + } else { + qDebug() << "Unknown value for scrollRegion" << m_parameters.at(0); + } + } else { + m_screen->currentCursor()->resetScrollArea(); + } + m_screen->currentCursor()->moveOrigin(); + break; + case FinalBytesNoIntermediate::Reserved3: + case FinalBytesNoIntermediate::Reserved4: + case FinalBytesNoIntermediate::Reserved5: + case FinalBytesNoIntermediate::Reserved6: + case FinalBytesNoIntermediate::Reserved7: + case FinalBytesNoIntermediate::Reserved8: + case FinalBytesNoIntermediate::Reserved9: + case FinalBytesNoIntermediate::Reserveda: + case FinalBytesNoIntermediate::Reservedb: + case FinalBytesNoIntermediate::Reservedc: + case FinalBytesNoIntermediate::Reservedd: + case FinalBytesNoIntermediate::Reservede: + case FinalBytesNoIntermediate::Reservedf: + default: + qDebug() << "Unhandeled CSI" << FinalBytesNoIntermediate::FinalBytesNoIntermediate(character); + break; + } + tokenFinished(); + } + } + } +} + +void Parser::decodeOSC(uchar character) +{ + if (!m_parameters.size() && + character >= 0x30 && character <= 0x3f) { + decodeParameters(character); + } else { + appendParameter(); + if (m_decode_osc_state == None) { + if (m_parameters.size() != 1) { + tokenFinished(); + return; + } + + switch (m_parameters.at(0)) { + case 0: + m_decode_osc_state = ChangeWindowAndIconName; + break; + case 1: + m_decode_osc_state = ChangeIconTitle; + break; + case 2: + m_decode_osc_state = ChangeWindowTitle; + break; + default: + m_decode_osc_state = Unknown; + break; + } + } else { + if (character == 0x07) { + if (m_decode_osc_state == ChangeWindowAndIconName || + m_decode_osc_state == ChangeWindowTitle) { + QString title = QString::fromUtf8(m_current_data.mid(m_current_token_start+4, + m_current_position - m_current_token_start -1)); + m_screen->setTitle(title); + } + tokenFinished(); + } + } + } +} + +void Parser::decodeCharacterSet(uchar character) +{ + if (m_decode_graphics_set < 0 || m_decode_graphics_set > (int) (sizeof(m_graphic_codecs) / sizeof(*m_graphic_codecs))) { + qDebug() << "Parser state is illigal. m_decode_graphics_set is: " << m_decode_graphics_set << "array size is:" << (sizeof(m_graphic_codecs) / sizeof(*m_graphic_codecs)); + m_decode_graphics_set = 0; + return; + } + switch(character) { + case '0': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::dec_special_graphics); + break; + case '4': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_dutch); + break; + case '5': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_finnish); + break; + case '6': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_norwegian_danish); + break; + case '7': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_swedish); + break; + case 'A': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_british); + break; + case 'B': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::ascii); + break; + case 'C': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_finnish); + break; + case 'R': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_french); + break; + case 'Q': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_french_canadian); + break; + case 'K': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_german); + break; + case 'Y': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_italian); + break; + case 'E': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_norwegian_danish); + break; + case 'Z': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_spanish); + break; + case 'H': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_swedish); + break; + case '=': + m_graphic_codecs[m_decode_graphics_set] = codecForCharacterset(CharacterSet::nrc_swiss); + break; + default: + qDebug() << "Not supported Character set!" << character << (char) character; + } + tokenFinished(); +} + +void Parser::decodeFontSize(uchar character) +{ + switch(character) { + case '8': + if (yat_parser_debug) + qDebug() << "Filling screen with 'E'"; + m_screen->fill(QChar('E')); + break; + default: + qDebug() << "Failed to decode font size for" << character; + break; + } + tokenFinished(); +} + +void Parser::setMode(int mode) +{ + switch(mode) { +//Guarded area transfer GATM* 1 +//Keyboard action KAM 2 +//Control representation CRM† 3 +//Insert/replace IRM 4 + case 4: + m_screen->currentCursor()->setInsertMode(Cursor::Insert); + break; +//Status reporting transfer SRTM* 5 +//Vertical editing VEM* 7 +//Horizontal editing HEM* 10 +//Positioning unit PUM* 11 +//Send/receive SRM 12 +//Format effector action FEAM* 13 +//Format effector transfer FETM* 14 +//Multiple area transfer MATM* 15 +//Transfer termination TTM* 16 +//Selected area transfer SATM* 17 +//Tabulation stop TSM* 18 +//Editing boundary EBM* 19 +//Line feed/new line LNM 20 + case 20: + m_lnm_mode_set = true; + break; + default: + qDebug() << "Unhandeled setMode" << mode; + break; + } +} + +void Parser::setDecMode(int mode) +{ +//taken from http://invisible-island.net/xterm/ctlseqs/ctlseqs.html + switch (mode) { +//1 -> Application Cursor Keys (DECCKM). + case 1: + m_screen->setApplicationCursorKeysMode(true); + break; +//2 -> Designate USASCII for character sets G0-G3 (DECANM), and set VT100 mode. +//3 -> 132 Column Mode (DECCOLM). + case 3: + m_screen->emitRequestWidth(132); + m_screen->emitRequestHeight(24); + m_screen->clear(); + m_screen->currentCursor()->moveOrigin(); + m_screen->currentCursor()->resetScrollArea(); + break; +//4 -> Smooth (Slow) Scroll (DECSCLM). + case 4: + m_screen->setFastScroll(false); + break; +//5 -> Reverse Video (DECSCNM). + case 5: + m_screen->colorPalette()->setInverseDefaultColors(true); + break; +//6 -> Origin Mode (DECOM). + case 6: + m_screen->currentCursor()->setOriginAtMargin(true); + break; +//7 -> Wraparound Mode (DECAWM). + case 7: + m_screen->currentCursor()->setWrapAround(true); + break; + +//8 -> Auto-repeat Keys (DECARM). +//9 -> Send Mouse X & Y on button press. See the section Mouse Tracking. +//10 -> Show toolbar (rxvt). +//12 -> Start Blinking Cursor (att610). + case 12: + m_screen->currentCursor()->setBlinking(true); + break; +//18 -> Print form feed (DECPFF). +//19 -> Set print extent to full screen (DECPEX). +//25 -> Show Cursor (DECTCEM). + case 25: + m_screen->currentCursor()->setVisible(true); + break; +//30 -> Show scrollbar (rxvt). +//35 -> Enable font-shifting functions (rxvt). +//38 -> Enter Tektronix Mode (DECTEK). +//40 -> Allow 80 → 132 Mode. +//41 -> more(1) fix (see curses resource). +//42 -> Enable Nation Replacement Character sets (DECNRCM). +//44 -> Turn On Margin Bell. +//45 -> Reverse-wraparound Mode. +//46 -> Start Logging. This is normally disabled by a compile-time option. +//47 -> Use Alternate Screen Buffer. (This may be disabled by the titeInhibit resource). + case 47: + m_screen->useAlternateScreenBuffer(); + break; +//66 -> Application keypad (DECNKM). +//67 -> Backarrow key sends backspace (DECBKM). +//69 -> Enable left and right margin mode (DECLRMM), VT420 and up. +//95 -> Do not clear screen when DECCOLM is set/reset (DECNCSM), VT510 and up. +//1000 → Send Mouse X & Y on button press and release. See the section Mouse Tracking. +//1001 -> Use Hilite Mouse Tracking. +//1002 -> Use Cell Motion Mouse Tracking. +//1003 -> Use All Motion Mouse Tracking. +//1004 -> Send FocusIn/FocusOut events. +//1005 -> Enable UTF-8 Mouse Mode. +//1006 -> Enable SGR Mouse Mode. +//1007 -> Enable Alternate Scroll Mode. +//1010 -> Scroll to bottom on tty output (rxvt). +//1015 -> Enable urxvt Mouse Mode. +//1011 -> Scroll to bottom on key press (rxvt). +//1034 -> Interpret "meta" key, sets eighth bit. (enables the eightBitInput resource). +//1035 -> Enable special modifiers for Alt and NumLock keys. (This enables the numLock resource). +//1036 -> Send ESC when Meta modifies a key. (This enables the metaSendsEscape resource). +//1037 -> Send DEL from the editing-keypad Delete key. +//1039 -> Send ESC when Alt modifies a key. (This enables the altSendsEscape resource). +//1040 -> Keep selection even if not highlighted. (This enables the keepSelection resource). +//1041 -> Use the CLIPBOARD selection. (This enables the selectToClipboard resource). +//1042 -> Enable Urgency window manager hint when Control-G is received. (This enables the bellIsUrgent resource). +//1043 -> Enable raising of the window when Control-G is received. (enables the popOnBell resource). +//1047 -> Use Alternate Screen Buffer. (This may be disabled by the titeInhibit resource). + case 1047: + m_screen->useAlternateScreenBuffer(); + break; +//1048 -> Save cursor as in DECSC. (This may be disabled by the titeInhibit resource). + case 1048: + m_screen->saveCursor(); + break; +//1049 -> Save cursor as in DECSC and use Alternate Screen Buffer, clearing it first. (This may be disabled by the titeInhibit resource). This combines the effects of the 1047 and 1048 modes. Use this with terminfo-based applications rather than the 47 mode. + case 1049: + m_screen->saveCursor(); + m_screen->useAlternateScreenBuffer(); + break; +//1050 -> Set terminfo/termcap function-key mode. +//1051 -> Set Sun function-key mode. +//1052 -> Set HP function-key mode. +//1053 -> Set SCO function-key mode. +//1060 -> Set legacy keyboard emulation (X11R6). +//1061 -> Set VT220 keyboard emulation. +//2004 -> Set bracketed paste mode + default: + qDebug() << "Unhandeled setDecMode" << mode; + } +} + +void Parser::resetMode(int mode) +{ + switch(mode) { +//Guarded area transfer GATM* 1 +//Keyboard action KAM 2 +//Control representation CRM† 3 +//Insert/replace IRM 4 + case 4: + m_screen->currentCursor()->setInsertMode(Cursor::Replace); + break; +//Status reporting transfer SRTM* 5 +//Vertical editing VEM* 7 +//Horizontal editing HEM* 10 +//Positioning unit PUM* 11 +//Send/receive SRM 12 +//Format effector action FEAM* 13 +//Format effector transfer FETM* 14 +//Multiple area transfer MATM* 15 +//Transfer termination TTM* 16 +//Selected area transfer SATM* 17 +//Tabulation stop TSM* 18 +//Editing boundary EBM* 19 +//Line feed/new line LNM 20 + case 20: + m_lnm_mode_set = false; + break; + default: + qDebug() << "Unhandeled resetMode" << mode; + break; + } +} + +void Parser::resetDecMode(int mode) +{ + switch(mode) { +//taken from http://invisible-island.net/xterm/ctlseqs/ctlseqs.html +//1 -> Normal Cursor Keys (DECCKM). + case 1: + m_screen->setApplicationCursorKeysMode(false); + break; +//2 -> Designate VT52 mode (DECANM). +//3 -> 80 Column Mode (DECCOLM). + case 3: + m_screen->emitRequestWidth(80); + m_screen->emitRequestHeight(24); + m_screen->clear(); + m_screen->currentCursor()->moveOrigin(); + m_screen->currentCursor()->resetScrollArea(); + break; +//4 -> Jump (Fast) Scroll (DECSCLM). + case 4: + m_screen->setFastScroll(true); + break; +//5 -> Normal Video (DECSCNM). + case 5: + m_screen->colorPalette()->setInverseDefaultColors(false); + break; +//6 -> Normal Cursor Mode (DECOM). + case 6: + m_screen->currentCursor()->setOriginAtMargin(false); + break; +//7 -> No Wraparound Mode (DECAWM). + case 7: + m_screen->currentCursor()->setWrapAround(false); + break; +//8 -> No Auto-repeat Keys (DECARM). +//9 -> Don’t send Mouse X & Y on button press. +//10 -> Hide toolbar (rxvt). +//12 -> Stop Blinking Cursor (att610). + case 12: + m_screen->currentCursor()->setBlinking(false); + break; +//18 -> Don’t print form feed (DECPFF). +//19 -> Limit print to scrolling region (DECPEX). +//25 -> Hide Cursor (DECTCEM). + case 25: + m_screen->currentCursor()->setVisible(false); + break; +//30 -> Don’t show scrollbar (rxvt). +//35 -> Disable font-shifting functions (rxvt). +//40 -> Disallow 80 → 132 Mode. +//41 -> No more(1) fix (see curses resource). +//42 -> Disable Nation Replacement Character sets (DECNRCM). +//44 -> Turn Off Margin Bell. +//45 -> No Reverse-wraparound Mode. +//46 -> Stop Logging. (This is normally disabled by a compile-time option). +//47 -> Use Normal Screen Buffer. + case 47: + m_screen->useNormalScreenBuffer(); + break; +//66 -> Numeric keypad (DECNKM). +//67 -> Backarrow key sends delete (DECBKM). +//69 -> Disable left and right margin mode (DECLRMM), VT420 and up. +//95 -> Clear screen when DECCOLM is set/reset (DECNCSM), VT510 and up. +//1000 -> Don’t send Mouse X & Y on button press and release. See the section Mouse Tracking. +//1001 -> Don’t use Hilite Mouse Tracking. +//1002 -> Don’t use Cell Motion Mouse Tracking. +//1003 -> Don’t use All Motion Mouse Tracking. +//1004 -> Don’t send FocusIn/FocusOut events. +//1005 -> Disable UTF-8 Mouse Mode. +//1006 -> Disable SGR Mouse Mode. +//1007 -> Disable Alternate Scroll Mode. +//1010 -> Don’t scroll to bottom on tty output (rxvt). +//1015 -> Disable urxvt Mouse Mode. +//1011 -> Don’t scroll to bottom on key press (rxvt). +//1034 -> Don’t interpret "meta" key. (This disables the eightBitInput resource). +//1035 -> Disable special modifiers for Alt and NumLock keys. (This disables the numLock resource). +//1036 -> Don’t send ESC when Meta modifies a key. (This disables the metaSendsEscape resource). +//1037 -> Send VT220 Remove from the editing-keypad Delete key. +//1039 -> Don’t send ESC when Alt modifies a key. (This disables the altSendsEscape resource). +//1040 -> Do not keep selection when not highlighted. (This disables the keepSelection resource). +//1041 -> Use the PRIMARY selection. (This disables the selectToClipboard resource). +//1042 -> Disable Urgency window manager hint when Control-G is received. (This disables the bellIsUrgent resource). +//1043 -> Disable raising of the window when Control-G is received. (This disables the popOnBell resource). +//1047 -> Use Normal Screen Buffer, clearing screen first if in the Alternate Screen. (This may be disabled by the titeInhibit resource). + case 1047: + m_screen->useNormalScreenBuffer(); + break; +//1048 -> Restore cursor as in DECRC. (This may be disabled by the titeInhibit resource). + case 1048: + m_screen->restoreCursor(); + break; +//1049 -> Use Normal Screen Buffer and restore cursor as in DECRC. (This may be disabled by the titeInhibit resource). This combines the effects of the 1047 and 1048 modes. Use this with terminfo-based applications rather than the 47 mode. + case 1049: + m_screen->restoreCursor(); + m_screen->useNormalScreenBuffer(); + break; +//1050 -> Reset terminfo/termcap function-key mode. +//1051 -> Reset Sun function-key mode. +//1052 -> Reset HP function-key mode. +//1053 -> Reset SCO function-key mode. +//1060 -> Reset legacy keyboard emulation (X11R6). +//1061 -> Reset keyboard emulation to Sun/PC style. +//2004 -> Reset bracketed paste mode + default: + qDebug() << "Unhandeled resetDecMode" << mode; + break; + } +} + +void Parser::handleSGR() +{ + for (int i = 0; i < m_parameters.size();i++) { + switch(m_parameters.at(i)) { + case 0: + // m_screen->setTextStyle(TextStyle::Normal); + m_screen->currentCursor()->resetStyle(); + break; + case 1: + m_screen->currentCursor()->setTextStyle(TextStyle::Bold); + break; + case 4: + m_screen->currentCursor()->setTextStyle(TextStyle::Underlined); + break; + case 5: + m_screen->currentCursor()->setTextStyle(TextStyle::Blinking); + break; + case 7: + m_screen->currentCursor()->setTextStyle(TextStyle::Inverse); + break; + case 8: + qDebug() << "SGR: Hidden text not supported"; + break; + case 22: + m_screen->currentCursor()->setTextStyle(TextStyle::Bold, false); + break; + case 24: + m_screen->currentCursor()->setTextStyle(TextStyle::Underlined, false); + break; + case 25: + m_screen->currentCursor()->setTextStyle(TextStyle::Blinking, false); + break; + case 27: + m_screen->currentCursor()->setTextStyle(TextStyle::Inverse, false); + break; + case 28: + qDebug() << "SGR: Visible text is allways on"; + break; + case 30: + case 31: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + // case 38: + case 39: + case 40: + case 41: + case 42: + case 43: + case 44: + case 45: + case 46: + case 47: + // case 38: + case 49: + m_screen->currentCursor()->setTextStyleColor(m_parameters.at(i)); + break; + default: + qDebug() << "Unknown SGR" << m_parameters.at(i); + break; + } + + } +} + +void Parser::tokenFinished() +{ + m_decode_state = PlainText; + m_decode_osc_state = None; + + m_parameters.clear(); + m_parameter_string.clear(); + + m_current_token_start = m_current_position + 1; + m_intermediate_char = 0; + + m_parameters_expecting_more = false; + m_dec_mode = false; + m_gt_param = false; + m_contains_only_latin = true; +} + +void Parser::appendParameter() +{ + if (m_parameter_string.size()) { + m_parameters.append(m_parameter_string.toUShort()); + m_parameter_string.clear(); + m_parameters_expecting_more = false; + } +} + +void Parser::handleDefaultParameters(int defaultValue) +{ + for (int i = 0; i < m_parameters.size(); i++) { + if (m_parameters.at(i) == INT_MIN) + m_parameters.replace(i, defaultValue); + } + if (m_parameters_expecting_more) + m_parameters.append(defaultValue); +} + +QDebug operator<<(QDebug debug, Parser::DecodeState decodeState) +{ + switch(decodeState) { + case Parser::PlainText: + debug << "PlainText"; + break; + case Parser::DecodeC0: + debug << "DecodeC0"; + break; + case Parser::DecodeC1_7bit: + debug << "DecodeC1_7bit"; + break; + case Parser::DecodeCSI: + debug << "DecodeCSI"; + break; + case Parser::DecodeOSC: + debug << "DecodeOSC"; + break; + case Parser::DecodeCharacterSet: + debug << "DecodeCharacterSet"; + break; + case Parser::DecodeFontSize: + debug << "DecodeFontSize"; + break; + } + return debug; +} diff --git a/yat/backend/parser.h b/yat/backend/parser.h new file mode 100644 index 0000000..9ee598f --- /dev/null +++ b/yat/backend/parser.h @@ -0,0 +1,110 @@ +/******************************************************************************* +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#ifndef PARSER_H +#define PARSER_H + +#include +#include +#include + +#include "controll_chars.h" +#include "utf8_decoder.h" + +class Screen; + +class Parser +{ +public: + Parser(Screen *screen); + + void addData(const QByteArray &data); + +private: + + enum DecodeState { + PlainText, + DecodeC0, + DecodeC1_7bit, + DecodeCSI, + DecodeOSC, + DecodeCharacterSet, + DecodeFontSize + }; + + enum DecodeOSCState { + None, + ChangeWindowAndIconName, + ChangeIconTitle, + ChangeWindowTitle, + Unknown + }; + + void decodeC0(uchar character); + void decodeC1_7bit(uchar character); + void decodeParameters(uchar character); + void decodeCSI(uchar character); + void decodeOSC(uchar character); + void decodeCharacterSet(uchar character); + void decodeFontSize(uchar character); + + void setMode(int mode); + void setDecMode(int mode); + void resetMode(int mode); + void resetDecMode(int mode); + + void handleSGR(); + + void tokenFinished(); + + void appendParameter(); + void handleDefaultParameters(int defaultValue); + + DecodeState m_decode_state; + DecodeOSCState m_decode_osc_state; + + QByteArray m_current_data; + + int m_current_token_start; + int m_current_position; + + QChar m_intermediate_char; + + QByteArray m_parameter_string; + QVector m_parameters; + bool m_parameters_expecting_more; + bool m_dec_mode; + bool m_gt_param; + bool m_lnm_mode_set; + bool m_contains_only_latin; + + int m_decode_graphics_set; + QTextCodec *m_graphic_codecs[4]; + Utf8Decoder m_utf8_decoder; + + Screen *m_screen; + friend QDebug operator<<(QDebug debug, DecodeState decodeState); +}; +QDebug operator<<(QDebug debug, Parser::DecodeState decodeState); + +#endif // PARSER_H diff --git a/yat/backend/screen.cpp b/yat/backend/screen.cpp new file mode 100644 index 0000000..f003c6f --- /dev/null +++ b/yat/backend/screen.cpp @@ -0,0 +1,620 @@ +/****************************************************************************** + * Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +******************************************************************************/ + +#include "screen.h" + +#include "screen_data.h" +#include "block.h" +#include "cursor.h" +#include "text.h" +#include "scrollback.h" +#include "selection.h" + +#include "controll_chars.h" +#include "character_sets.h" + +#include +#include +#include + +#include + +#include + +Screen::Screen(QObject *parent) + : QObject(parent) + , m_palette(new ColorPalette(this)) + , m_parser(this) + , m_timer_event_id(0) + , m_width(1) + , m_height(0) + , m_primary_data(new ScreenData(500, this)) + , m_alternate_data(new ScreenData(0, this)) + , m_current_data(m_primary_data) + , m_old_current_data(m_primary_data) + , m_selection(new Selection(this)) + , m_flash(false) + , m_cursor_changed(false) + , m_application_cursor_key_mode(false) + , m_fast_scroll(true) + , m_default_background(m_palette->normalColor(ColorPalette::DefaultBackground)) +{ + Cursor *cursor = new Cursor(this); + m_cursor_stack << cursor; + m_new_cursors << cursor; + + connect(m_primary_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged())); + connect(m_primary_data, &ScreenData::contentModified, + this, &Screen::contentModified); + connect(m_palette, SIGNAL(changed()), this, SLOT(paletteChanged())); + + setHeight(25); + setWidth(80); + + connect(&m_pty, &YatPty::readyRead, this, &Screen::readData); + connect(&m_pty, SIGNAL(hangupReceived()),qGuiApp, SLOT(quit())); + +} + +Screen::~Screen() +{ + + for(int i = 0; i < m_to_delete.size(); i++) { + delete m_to_delete.at(i); + } + //m_to_delete.clear(); + + delete m_primary_data; + delete m_alternate_data; +} + + +QColor Screen::defaultForgroundColor() const +{ + return m_palette->normalColor(ColorPalette::DefaultForground); +} + +QColor Screen::defaultBackgroundColor() const +{ + return m_palette->normalColor(ColorPalette::DefaultBackground); +} + +void Screen::emitRequestHeight(int newHeight) +{ + emit requestHeightChange(newHeight); +} + +void Screen::setHeight(int height) +{ + if (height == m_height) + return; + + emit heightAboutToChange(height, currentCursor()->new_y(), currentScreenData()->scrollback()->height()); + + m_height = height; + + m_pty.setHeight(height, height * 10); + + emit heightChanged(); +} + +int Screen::height() const +{ + return m_height; +} + +int Screen::contentHeight() const +{ + return currentScreenData()->contentHeight(); +} + +void Screen::emitRequestWidth(int newWidth) +{ + emit requestWidthChange(newWidth); +} + +void Screen::setWidth(int width) +{ + if (width == m_width) + return; + + emit widthAboutToChange(width); + + m_width = width; + + m_pty.setWidth(width, width * 10); + + emit widthChanged(); +} + +int Screen::width() const +{ + return m_width; +} + +void Screen::useAlternateScreenBuffer() +{ + if (m_current_data == m_primary_data) { + disconnect(m_primary_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged())); + disconnect(m_primary_data, &ScreenData::contentModified, this, &Screen::contentModified); + m_current_data = m_alternate_data; + m_current_data->clear(); + connect(m_alternate_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged())); + connect(m_primary_data, &ScreenData::contentModified, this, &Screen::contentModified); + emit contentHeightChanged(); + } +} + +void Screen::useNormalScreenBuffer() +{ + if (m_current_data == m_alternate_data) { + disconnect(m_alternate_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged())); + disconnect(m_alternate_data, &ScreenData::contentModified, this, &Screen::contentModified); + m_current_data = m_primary_data; + connect(m_primary_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged())); + connect(m_alternate_data, &ScreenData::contentModified, this, &Screen::contentModified); + emit contentHeightChanged(); + } +} + +TextStyle Screen::defaultTextStyle() const +{ + TextStyle style; + style.style = TextStyle::Normal; + style.forground = ColorPalette::DefaultForground; + style.background = ColorPalette::DefaultBackground; + return style; +} + +void Screen::saveCursor() +{ + Cursor *new_cursor = new Cursor(this); + if (m_cursor_stack.size()) + m_cursor_stack.last()->setVisible(false); + m_cursor_stack << new_cursor; + m_new_cursors << new_cursor; +} + +void Screen::restoreCursor() +{ + if (m_cursor_stack.size() <= 1) + return; + + m_delete_cursors.append(m_cursor_stack.takeLast()); + m_cursor_stack.last()->setVisible(true); +} + +void Screen::clearScreen() +{ + currentScreenData()->clear(); +} + + +ColorPalette *Screen::colorPalette() const +{ + return m_palette; +} + +void Screen::fill(const QChar character) +{ + currentScreenData()->fill(character); +} + +void Screen::clear() +{ + fill(QChar(' ')); +} + +void Screen::setFastScroll(bool fast) +{ + m_fast_scroll = fast; +} + +bool Screen::fastScroll() const +{ + return m_fast_scroll; +} + +Selection *Screen::selection() const +{ + return m_selection; +} + +void Screen::doubleClicked(const QPointF &clicked) +{ + Q_UNUSED(clicked); + //int start, end; + //currentScreenData()->getDoubleClickSelectionArea(clicked, &start, &end); + //setSelectionAreaStart(QPointF(start,clicked.y())); + //setSelectionAreaEnd(QPointF(end,clicked.y())); +} + +void Screen::setTitle(const QString &title) +{ + m_title = title; + emit screenTitleChanged(); +} + +QString Screen::title() const +{ + return m_title; +} + +void Screen::scheduleFlash() +{ + m_flash = true; +} + +void Screen::printScreen() const +{ + currentScreenData()->printStyleInformation(); + qDebug() << "Total height: " << currentScreenData()->contentHeight(); +} + +void Screen::scheduleEventDispatch() +{ + if (!m_timer_event_id) { + m_timer_event_id = startTimer(1); + m_time_since_initiated.restart(); + } + + m_time_since_parsed.restart(); +} + +void Screen::dispatchChanges() +{ + if (m_old_current_data != m_current_data) { + m_old_current_data->releaseTextObjects(); + m_old_current_data = m_current_data; + } + + currentScreenData()->dispatchLineEvents(); + emit dispatchTextSegmentChanges(); + + static int max_to_delete_size = 0; + if (max_to_delete_size < m_to_delete.size()) { + max_to_delete_size = m_to_delete.size(); + qDebug() << "TO DELETE SIZE :" << max_to_delete_size; + } + + if (m_flash) { + m_flash = false; + emit flash(); + } + + for (int i = 0; i < m_delete_cursors.size(); i++) { + int new_index = m_new_cursors.indexOf(m_delete_cursors.at(i)); + if (new_index >= 0) + m_new_cursors.remove(new_index); + delete m_delete_cursors.at(i); + } + m_delete_cursors.clear(); + + for (int i = 0; i < m_new_cursors.size(); i++) { + emit cursorCreated(m_new_cursors.at(i)); + } + m_new_cursors.clear(); + + for (int i = 0; i < m_cursor_stack.size(); i++) { + m_cursor_stack[i]->dispatchEvents(); + } + + m_selection->dispatchChanges(); +} + +void Screen::sendPrimaryDA() +{ + m_pty.write(QByteArrayLiteral("\033[?6c")); + +} + +void Screen::sendSecondaryDA() +{ + m_pty.write(QByteArrayLiteral("\033[>1;95;0c")); +} + +void Screen::setApplicationCursorKeysMode(bool enable) +{ + m_application_cursor_key_mode = enable; +} + +bool Screen::applicationCursorKeyMode() const +{ + return m_application_cursor_key_mode; +} + +void Screen::ensureVisiblePages(int top_line) +{ + currentScreenData()->ensureVisiblePages(top_line); +} + +static bool hasControll(Qt::KeyboardModifiers modifiers) +{ +#ifdef Q_OS_MAC + return modifiers & Qt::MetaModifier; +#else + return modifiers & Qt::ControlModifier; +#endif +} + +static bool hasMeta(Qt::KeyboardModifiers modifiers) +{ +#ifdef Q_OS_MAC + return modifiers & Qt::ControlModifier; +#else + return modifiers & Qt::MetaModifier; +#endif +} + +void Screen::sendKey(const QString &text, Qt::Key key, Qt::KeyboardModifiers modifiers) +{ + +// if (key == Qt::Key_Control) +// printScreen(); + /// UGH, this function should be re-written + char escape = '\0'; + char control = '\0'; + char code = '\0'; + QVector parameters; + bool found = true; + + switch(key) { + case Qt::Key_Up: + escape = C0::ESC; + if (m_application_cursor_key_mode) + control = C1_7bit::SS3; + else + control = C1_7bit::CSI; + + code = 'A'; + break; + case Qt::Key_Right: + escape = C0::ESC; + if (m_application_cursor_key_mode) + control = C1_7bit::SS3; + else + control = C1_7bit::CSI; + + code = 'C'; + break; + case Qt::Key_Down: + escape = C0::ESC; + if (m_application_cursor_key_mode) + control = C1_7bit::SS3; + else + control = C1_7bit::CSI; + + code = 'B'; + break; + case Qt::Key_Left: + escape = C0::ESC; + if (m_application_cursor_key_mode) + control = C1_7bit::SS3; + else + control = C1_7bit::CSI; + + code = 'D'; + break; + case Qt::Key_Insert: + escape = C0::ESC; + control = C1_7bit::CSI; + parameters.append(2); + code = '~'; + break; + case Qt::Key_Delete: + escape = C0::ESC; + control = C1_7bit::CSI; + parameters.append(3); + code = '~'; + break; + case Qt::Key_Home: + escape = C0::ESC; + control = C1_7bit::CSI; + parameters.append(1); + code = '~'; + break; + case Qt::Key_End: + escape = C0::ESC; + control = C1_7bit::CSI; + parameters.append(4); + code = '~'; + break; + case Qt::Key_PageUp: + escape = C0::ESC; + control = C1_7bit::CSI; + parameters.append(5); + code = '~'; + break; + case Qt::Key_PageDown: + escape = C0::ESC; + control = C1_7bit::CSI; + parameters.append(6); + code = '~'; + break; + case Qt::Key_F1: + case Qt::Key_F2: + case Qt::Key_F3: + case Qt::Key_F4: + if (m_application_cursor_key_mode) { + parameters.append((key & 0xff) - 37); + escape = C0::ESC; + control = C1_7bit::CSI; + code = '~'; + } + break; + case Qt::Key_F5: + case Qt::Key_F6: + case Qt::Key_F7: + case Qt::Key_F8: + case Qt::Key_F9: + case Qt::Key_F10: + case Qt::Key_F11: + case Qt::Key_F12: + if (m_application_cursor_key_mode) { + parameters.append((key & 0xff) - 36); + escape = C0::ESC; + control = C1_7bit::CSI; + code = '~'; + } + break; + case Qt::Key_Control: + case Qt::Key_Shift: + case Qt::Key_Alt: + case Qt::Key_AltGr: + return; + break; + default: + found = false; + } + + if (found) { + int term_mods = 0; + if (modifiers & Qt::ShiftModifier) + term_mods |= 1; + if (modifiers & Qt::AltModifier) + term_mods |= 2; + if (modifiers & Qt::ControlModifier) + term_mods |= 4; + + QByteArray toPty; + + if (term_mods) { + term_mods++; + parameters.append(term_mods); + } + if (escape) + toPty.append(escape); + if (control) + toPty.append(control); + if (parameters.size()) { + for (int i = 0; i < parameters.size(); i++) { + if (i) + toPty.append(';'); + toPty.append(QByteArray::number(parameters.at(i))); + } + } + if (code) + toPty.append(code); + m_pty.write(toPty); + + } else { + QString verifiedText = text.simplified(); + if (verifiedText.isEmpty()) { + switch (key) { + case Qt::Key_Return: + case Qt::Key_Enter: + verifiedText = "\r"; + break; + case Qt::Key_Backspace: + verifiedText = "\010"; + break; + case Qt::Key_Tab: + verifiedText = "\t"; + break; + case Qt::Key_Control: + case Qt::Key_Meta: + case Qt::Key_Alt: + case Qt::Key_Shift: + return; + case Qt::Key_Space: + verifiedText = " "; + break; + default: + return; + } + } + QByteArray to_pty; + QByteArray key_text; + if (hasControll(modifiers)) { + char key_char = verifiedText.toLocal8Bit().at(0); + key_text.append(key_char & 0x1F); + } else { + key_text = verifiedText.toUtf8(); + } + + if (modifiers & Qt::AltModifier) { + to_pty.append(C0::ESC); + } + + if (hasMeta(modifiers)) { + to_pty.append(C0::ESC); + to_pty.append('@'); + to_pty.append(FinalBytesNoIntermediate::Reserved3); + } + + to_pty.append(key_text); + m_pty.write(to_pty); + } +} + +YatPty *Screen::pty() +{ + return &m_pty; +} + +Text *Screen::createTextSegment(const TextStyleLine &style_line) +{ + Q_UNUSED(style_line); + Text *to_return; + if (m_to_delete.size()) { + to_return = m_to_delete.takeLast(); + to_return->setVisible(true); + } else { + to_return = new Text(this); + emit textCreated(to_return); + } + + return to_return; +} + +void Screen::releaseTextSegment(Text *text) +{ + m_to_delete.append(text); +} + +void Screen::readData(const QByteArray &data) +{ + m_parser.addData(data); + + scheduleEventDispatch(); +} + +void Screen::paletteChanged() +{ + QColor new_default = m_palette->normalColor(ColorPalette::DefaultBackground); + if (new_default != m_default_background) { + m_default_background = new_default; + emit defaultBackgroundColorChanged(); + } +} + + + +void Screen::timerEvent(QTimerEvent *) +{ + if (m_timer_event_id && (m_time_since_parsed.elapsed() > 3 || m_time_since_initiated.elapsed() > 8)) { + killTimer(m_timer_event_id); + m_timer_event_id = 0; + dispatchChanges(); + } +} diff --git a/yat/backend/screen.h b/yat/backend/screen.h new file mode 100644 index 0000000..e6574a6 --- /dev/null +++ b/yat/backend/screen.h @@ -0,0 +1,188 @@ +/******************************************************************************* +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#ifndef TERMINALSCREEN_H +#define TERMINALSCREEN_H + +#include + +#include "color_palette.h" +#include "parser.h" +#include "yat_pty.h" +#include "text_style.h" + +#include +#include +#include +#include + +class Block; +class Cursor; +class Text; +class ScreenData; +class Selection; + +class Screen : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) + Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) + Q_PROPERTY(int contentHeight READ contentHeight NOTIFY contentHeightChanged) + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY screenTitleChanged) + Q_PROPERTY(Selection *selection READ selection CONSTANT) + Q_PROPERTY(QColor defaultBackgroundColor READ defaultBackgroundColor NOTIFY defaultBackgroundColorChanged) + +public: + explicit Screen(QObject *parent = 0); + ~Screen(); + + void emitRequestHeight(int newHeight); + void setHeight(int height); + int height() const; + int contentHeight() const; + + void emitRequestWidth(int newWidth); + void setWidth(int width); + int width() const; + + ScreenData *currentScreenData() const { return m_current_data; } + void useAlternateScreenBuffer(); + void useNormalScreenBuffer(); + + Cursor *currentCursor() const { return m_cursor_stack.last(); } + void saveCursor(); + void restoreCursor(); + + TextStyle defaultTextStyle() const; + + QColor defaultForgroundColor() const; + QColor defaultBackgroundColor() const; + + ColorPalette *colorPalette() const; + + void clearScreen(); + + void fill(const QChar character); + void clear(); + + void setFastScroll(bool fast); + bool fastScroll() const; + + Selection *selection() const; + + Q_INVOKABLE void doubleClicked(const QPointF &clicked); + + void setTitle(const QString &title); + QString title() const; + + void scheduleFlash(); + + Q_INVOKABLE void printScreen() const; + + void scheduleEventDispatch(); + void dispatchChanges(); + + void sendPrimaryDA(); + void sendSecondaryDA(); + + void setApplicationCursorKeysMode(bool enable); + bool applicationCursorKeyMode() const; + + Q_INVOKABLE void sendKey(const QString &text, Qt::Key key, Qt::KeyboardModifiers modifiers); + + YatPty *pty(); + + Q_INVOKABLE void ensureVisiblePages(int top_line); + Text *createTextSegment(const TextStyleLine &style_line); + void releaseTextSegment(Text *text); + +public slots: + void readData(const QByteArray &data); + void paletteChanged(); + +signals: + void reset(); + + void flash(); + + void dispatchLineChanges(); + void dispatchTextSegmentChanges(); + + void screenTitleChanged(); + + void textCreated(Text *text); + void cursorCreated(Cursor *cursor); + + void requestHeightChange(int newHeight); + void heightAboutToChange(int height, int currentCursorLine, int currentScrollBackHeight); + void heightChanged(); + void contentHeightChanged(); + + void requestWidthChange(int newWidth); + void widthAboutToChange(int width); + void widthChanged(); + + void defaultBackgroundColorChanged(); + + void contentModified(size_t lineModified, int lineDiff, int contentDiff); +protected: + void timerEvent(QTimerEvent *); + +private: + ColorPalette *m_palette; + YatPty m_pty; + Parser m_parser; + QElapsedTimer m_time_since_parsed; + QElapsedTimer m_time_since_initiated; + + int m_timer_event_id; + int m_width; + int m_height; + + ScreenData *m_primary_data; + ScreenData *m_alternate_data; + ScreenData *m_current_data; + ScreenData *m_old_current_data; + + QVector m_cursor_stack; + QVector m_new_cursors; + QVector m_delete_cursors; + + QString m_title; + + Selection *m_selection; + + bool m_flash; + bool m_cursor_changed; + bool m_application_cursor_key_mode; + bool m_fast_scroll; + + QVector m_to_delete; + + QColor m_default_background; + + friend class ScreenData; +}; + +#endif // TERMINALSCREEN_H diff --git a/yat/backend/screen_data.cpp b/yat/backend/screen_data.cpp new file mode 100644 index 0000000..c7f178a --- /dev/null +++ b/yat/backend/screen_data.cpp @@ -0,0 +1,530 @@ +/******************************************************************************* + * Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#include "screen_data.h" + +#include "block.h" +#include "screen.h" +#include "scrollback.h" +#include "cursor.h" + +#include + +#include +#include + +ScreenData::ScreenData(size_t max_scrollback, Screen *screen) + : QObject(screen) + , m_screen(screen) + , m_scrollback(new Scrollback(max_scrollback, this)) + , m_screen_height(0) + , m_height(0) + , m_width(0) + , m_block_count(0) + , m_old_total_lines(0) +{ + connect(screen, SIGNAL(heightAboutToChange(int, int, int)), this, SLOT(setHeight(int, int, int))); + connect(screen, SIGNAL(widthAboutToChange(int)), this, SLOT(setWidth(int))); +} + +ScreenData::~ScreenData() +{ + for (auto it = m_screen_blocks.begin(); it != m_screen_blocks.end(); ++it) { + delete *it; + } + delete m_scrollback; +} + + +int ScreenData::contentHeight() const +{ + return m_height + m_scrollback->height(); +} + +void ScreenData::setHeight(int height, int currentCursorLine, int currentContentHeight) +{ + Q_UNUSED(currentContentHeight); + m_screen_height = height; + if (height == m_height) + return; + + if (m_height > height) { + const int to_remove = m_height - height; + const int remove_from_end = std::min((m_height -1) - currentCursorLine, to_remove); + const int remove_from_start = to_remove - remove_from_end; + + if (remove_from_end) { + remove_lines_from_end(remove_from_end); + } + if (remove_from_start) { + push_at_most_to_scrollback(remove_from_start); + } + } else { + ensure_at_least_height(height); + } +} + +void ScreenData::setWidth(int width) +{ + m_width = width; + + for (Block *block : m_screen_blocks) { + int before_count = block->lineCount(); + block->setWidth(width); + m_height += block->lineCount() - before_count; + } + + if (m_height > m_screen_height) { + push_at_most_to_scrollback(m_height - m_screen_height); + } else { + ensure_at_least_height(m_screen_height); + } + + m_scrollback->setWidth(width); +} + + +void ScreenData::clearToEndOfLine(const QPoint &point) +{ + auto it = it_for_row_ensure_single_line_block(point.y()); + (*it)->clearToEnd(point.x()); +} + +void ScreenData::clearToEndOfScreen(int y) +{ + auto it = it_for_row_ensure_single_line_block(y); + while(it != m_screen_blocks.end()) { + clearBlock(it); + ++it; + } +} + +void ScreenData::clearToBeginningOfLine(const QPoint &point) +{ + auto it = it_for_row_ensure_single_line_block(point.y()); + (*it)->clearCharacters(0,point.x()); +} + +void ScreenData::clearToBeginningOfScreen(int y) +{ + auto it = it_for_row_ensure_single_line_block(y); + if (it != m_screen_blocks.end()) + (*it)->clear(); + while(it != m_screen_blocks.begin()) { + --it; + clearBlock(it); + } +} + +void ScreenData::clearLine(const QPoint &point) +{ + (*it_for_row_ensure_single_line_block(point.y()))->clear(); +} + +void ScreenData::clear() +{ + for (auto it = m_screen_blocks.begin(); it != m_screen_blocks.end(); ++it) { + clearBlock(it); + } +} + +void ScreenData::releaseTextObjects() +{ + for (auto it = m_screen_blocks.begin(); it != m_screen_blocks.end(); ++it) { + (*it)->releaseTextObjects(); + } +} + +void ScreenData::clearCharacters(const QPoint &point, int to) +{ + auto it = it_for_row_ensure_single_line_block(point.y()); + (*it)->clearCharacters(point.x(),to); +} + +void ScreenData::deleteCharacters(const QPoint &point, int to) +{ + auto it = it_for_row(point.y()); + if (it == m_screen_blocks.end()) + return; + + int line_in_block = point.y() - (*it)->screenIndex(); + int chars_to_line = line_in_block * m_width; + + (*it)->deleteCharacters(chars_to_line + point.x(), chars_to_line + to); +} + +CursorDiff ScreenData::replace(const QPoint &point, const QString &text, const TextStyle &style, bool only_latin) +{ + return modify(point,text,style,true, only_latin); +} + +CursorDiff ScreenData::insert(const QPoint &point, const QString &text, const TextStyle &style, bool only_latin) +{ + return modify(point,text,style,false, only_latin); +} + + +void ScreenData::moveLine(int from, int to) +{ + if (from == to) + return; + + const size_t old_content_height = contentHeight(); + const int orig_to = to; + if (to > from) + to++; + auto from_it = it_for_row_ensure_single_line_block(from); + auto to_it = it_for_row_ensure_single_line_block(to); + + (*from_it)->clear(); + m_screen_blocks.splice(to_it, m_screen_blocks, from_it); + qDebug() << Q_FUNC_INFO << to; + emit contentModified(m_scrollback->height() + to, 1, content_height_diff(old_content_height)); +} + +void ScreenData::insertLine(int row, int topMargin) +{ + auto row_it = it_for_row(row + 1); + + const size_t old_content_height = contentHeight(); + + if (!topMargin && m_height >= m_screen_height) { + push_at_most_to_scrollback(1); + } else { + auto row_top_margin = it_for_row_ensure_single_line_block(topMargin); + if (row == topMargin) { + (*row_top_margin)->clear(); + return; + } + delete (*row_top_margin); + m_screen_blocks.erase(row_top_margin); + m_height--; + m_block_count--; + } + + Block *block_to_insert = new Block(m_screen); + m_screen_blocks.insert(row_it,block_to_insert); + m_height++; + m_block_count++; + + emit contentModified(m_scrollback->height() + row + 1, 1, content_height_diff(old_content_height)); +} + + +void ScreenData::fill(const QChar &character) +{ + clear(); + auto it = --m_screen_blocks.end(); + for (int i = 0; i < m_block_count; --it, i++) { + QString fill_str(m_screen->width(), character); + (*it)->replaceAtPos(0, fill_str, m_screen->defaultTextStyle()); + } +} + +void ScreenData::dispatchLineEvents() +{ + if (!m_block_count) + return; + const int scrollback_height = m_scrollback->height(); + int i = 0; + for (auto it = m_screen_blocks.begin(); it != m_screen_blocks.end(); ++it) { + int line = scrollback_height + i; + (*it)->setLine(line); + //(*it)->setScreenIndex(i); + (*it)->dispatchEvents(); + i+= (*it)->lineCount(); + } + + if (contentHeight() != m_old_total_lines) { + m_old_total_lines = contentHeight(); + emit contentHeightChanged(); + } +} + +void ScreenData::printRuler(QDebug &debug) const +{ + QString ruler = QString("|----i----").repeated((m_width/10)+1).append("|"); + debug << " " << (void *) this << ruler; +} + +void ScreenData::printStyleInformation() const +{ + auto it = m_screen_blocks.end(); + std::advance(it, -m_block_count); + for (int i = 0; it != m_screen_blocks.end(); ++it, i++) { + if (i % 5 == 0) { + QDebug debug = qDebug(); + debug << "Ruler:"; + printRuler(debug); + } + QDebug debug = qDebug(); + (*it)->printStyleList(debug); + } + qDebug() << "On screen height" << m_height; +} + +Screen *ScreenData::screen() const +{ + return m_screen; +} + +void ScreenData::ensureVisiblePages(int top_line) +{ + m_scrollback->ensureVisiblePages(top_line); +} + +Scrollback *ScreenData::scrollback() const +{ + return m_scrollback; +} + +void ScreenData::sendSelectionToClipboard(const QPoint &start, const QPoint &end, QClipboard::Mode mode) +{ + if (start.y() < 0) + return; + if (end.y() >= contentHeight()) + return; + + QString to_clip_board_buffer; + + bool started_in_scrollback = false; + if (size_t(start.y()) < m_scrollback->height()) { + started_in_scrollback = true; + QPoint end_scrollback = end; + if (size_t(end.y()) >= m_scrollback->height()) { + end_scrollback = QPoint(m_width, m_scrollback->height() - 1); + } + to_clip_board_buffer = m_scrollback->selection(start, end_scrollback); + } + + if (size_t(end.y()) >= m_scrollback->height()) { + QPoint start_in_screen; + if (started_in_scrollback) { + start_in_screen = QPoint(0,0); + } else { + start_in_screen = start; + start_in_screen.ry() -= m_scrollback->height(); + } + QPoint end_in_screen = end; + end_in_screen.ry() -= m_scrollback->height(); + + auto it = it_for_row(start_in_screen.y()); + size_t screen_index = (*it)->screenIndex(); + int start_pos = (start_in_screen.y() - (*it)->screenIndex()) * m_width + start.x(); + for (; it != m_screen_blocks.end(); ++it, start_pos = 0) { + int end_pos = (*it)->textSize(); + bool should_break = false; + if (size_t(screen_index + (*it)->lineCount()) > size_t(end_in_screen.y())) { + end_pos = (end_in_screen.y() - screen_index) * m_width + end_in_screen.x(); + should_break = true; + } + if (to_clip_board_buffer.size()) + to_clip_board_buffer += '\n'; + to_clip_board_buffer += (*it)->textLine()->mid(start_pos, end_pos - start_pos); + if (should_break) + break; + screen_index += (*it)->lineCount(); + } + } + QGuiApplication::clipboard()->setText(to_clip_board_buffer, mode); +} + +CursorDiff ScreenData::modify(const QPoint &point, const QString &text, const TextStyle &style, bool replace, bool only_latin) +{ + auto it = it_for_row(point.y()); + Block *block = *it; + const int start_char = (point.y() - block->screenIndex()) * m_width + point.x(); + const size_t lines_before = block->lineCount(); + const int lines_changed = + block->lineCountAfterModified(start_char, text.size(), replace) - lines_before; + const size_t old_content_height = contentHeight(); + m_height += lines_changed; + if (lines_changed > 0) { + int removed = 0; + auto to_merge_inn = it; + ++to_merge_inn; + while(removed < lines_changed && to_merge_inn != m_screen_blocks.end()) { + Block *to_be_reduced = *to_merge_inn; + bool remove_block = removed + to_be_reduced->lineCount() <= lines_changed; + int lines_to_remove = remove_block ? to_be_reduced->lineCount() : to_be_reduced->lineCount() - (lines_changed - removed); + block->moveLinesFromBlock(to_be_reduced, 0, lines_to_remove); + removed += lines_to_remove; + if (remove_block) { + delete to_be_reduced; + to_merge_inn = m_screen_blocks.erase(to_merge_inn); + m_block_count--; + } else { + ++to_merge_inn; + } + } + + m_height -= removed; + } + + if (m_height > m_screen_height) + push_at_most_to_scrollback(m_height - m_screen_height); + + if (replace) { + block->replaceAtPos(start_char, text, style, only_latin); + } else { + block->insertAtPos(start_char, text, style, only_latin); + } + int end_char = (start_char + text.size()) % m_width; + if (end_char == 0) + end_char = m_width -1; + + emit contentModified(m_scrollback->height() + point.y(), lines_changed, content_height_diff(old_content_height)); + return { lines_changed, end_char - point.x()}; +} + +void ScreenData::clearBlock(std::list::iterator line) +{ + int before_count = (*line)->lineCount(); + (*line)->clear(); + int diff_line = before_count - (*line)->lineCount(); + if (diff_line > 0) { + ++line; + for (int i = 0; i < diff_line; i++) { + m_screen_blocks.insert(line, new Block(m_screen)); + } + m_block_count+=diff_line; + } +} + +std::list::iterator ScreenData::it_for_row_ensure_single_line_block(int row) +{ + auto it = it_for_row(row); + const int index = (*it)->screenIndex(); + const int lines = (*it)->lineCount(); + + if (index == row && lines == 1) { + return it; + } + + int line_diff = row - index; + return split_out_row_from_block(it, line_diff); +} + +std::list::iterator ScreenData::split_out_row_from_block(std::list::iterator it, int row_in_block) +{ + int lines = (*it)->lineCount(); + + if (row_in_block == 0 && lines == 1) + return it; + + if (row_in_block == 0) { + auto insert_before = (*it)->takeLine(0); + insert_before->setScreenIndex(row_in_block); + m_block_count++; + return m_screen_blocks.insert(it,insert_before); + } else if (row_in_block == lines -1) { + auto insert_after = (*it)->takeLine(lines -1); + insert_after->setScreenIndex(row_in_block); + ++it; + m_block_count++; + return m_screen_blocks.insert(it, insert_after); + } + + auto half = (*it)->split(row_in_block); + ++it; + auto it_width_first = m_screen_blocks.insert(it, half); + auto the_one = half->takeLine(0); + m_block_count+=2; + return m_screen_blocks.insert(it_width_first,the_one); +} + +void ScreenData::push_at_most_to_scrollback(int lines) +{ + int pushed = 0; + auto it = m_screen_blocks.begin(); + while (it != m_screen_blocks.end() && pushed + (*it)->lineCount() <= lines) { + m_block_count--; + const int block_height = (*it)->lineCount(); + m_height -= block_height; + pushed += block_height; + m_scrollback->addBlock(*it); + it = m_screen_blocks.erase(it); + } +} + +void ScreenData::reclaim_at_least(int lines) +{ + int lines_reclaimed = 0; + while (m_scrollback->blockCount() && lines_reclaimed < lines) { + Block *block = m_scrollback->reclaimBlock(); + m_height += block->lineCount(); + lines_reclaimed += block->lineCount(); + m_block_count++; + m_screen_blocks.push_front(block); + } +} + +void ScreenData::remove_lines_from_end(int lines) +{ + int removed = 0; + auto it = m_screen_blocks.end(); + while (it != m_screen_blocks.begin() && removed < lines) { + --it; + const int block_height = (*it)->lineCount(); + if (removed + block_height <= lines) { + removed += block_height; + m_height -= block_height; + m_block_count--; + delete (*it); + it = m_screen_blocks.erase(it); + } else { + const int to_remove = lines - removed; + removed += to_remove; + m_height -= to_remove; + Block *block = *it; + for (int i = 0; i < to_remove; i++) { + block->removeLine(block->lineCount()-1); + } + } + } +} + +void ScreenData::ensure_at_least_height(int height) +{ + if (m_height > height) + return; + + int to_grow = height - m_height; + reclaim_at_least(to_grow); + + if (height > m_height) { + int to_insert = height - m_height; + for (int i = 0; i < to_insert; i++) { + m_screen_blocks.push_back(new Block(m_screen)); + } + m_height += to_insert; + m_block_count += to_insert; + } +} + +int ScreenData::content_height_diff(size_t old_content_height) +{ + const size_t content_height = contentHeight(); + return old_content_height < content_height ? content_height - old_content_height : + - int(old_content_height - content_height); +} diff --git a/yat/backend/screen_data.h b/yat/backend/screen_data.h new file mode 100644 index 0000000..53cbed9 --- /dev/null +++ b/yat/backend/screen_data.h @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#ifndef SCREENDATA_H +#define SCREENDATA_H + +#include "text_style.h" +#include "block.h" + +#include +#include +#include +#include + +#include +class Screen; +class Scrollback; + +class CursorDiff +{ +public: + int line; + int character; +}; + +class ScreenData : public QObject +{ +Q_OBJECT +public: + ScreenData(size_t max_scrollback, Screen *screen); + ~ScreenData(); + + int contentHeight() const; + + void clearToEndOfLine(const QPoint &pos); + void clearToEndOfScreen(int y); + void clearToBeginningOfLine(const QPoint &pos); + void clearToBeginningOfScreen(int y); + void clearLine(const QPoint &pos); + void clear(); + void releaseTextObjects(); + + void clearCharacters(const QPoint &pos, int to); + void deleteCharacters(const QPoint &pos, int to); + + CursorDiff replace(const QPoint &pos, const QString &text, const TextStyle &style, bool only_latin); + CursorDiff insert(const QPoint &pos, const QString &text, const TextStyle &style, bool only_latin); + + void moveLine(int from, int to); + void insertLine(int insertAt, int topMargin); + + void fill(const QChar &character); + + void dispatchLineEvents(); + + void printRuler(QDebug &debug) const; + void printStyleInformation() const; + + Screen *screen() const; + + void ensureVisiblePages(int top_line); + + Scrollback *scrollback() const; + + void sendSelectionToClipboard(const QPoint &start, const QPoint &end, QClipboard::Mode mode); + + inline std::list::iterator it_for_row(int row); +public slots: + void setHeight(int height, int currentCursorLine, int currentContentHeight); + void setWidth(int width); + +signals: + void contentHeightChanged(); + void contentModified(size_t lineModified, int lineDiff, int contentDiff); + +private: + CursorDiff modify(const QPoint &pos, const QString &text, const TextStyle &style, bool replace, bool only_latin); + void clearBlock(std::list::iterator line); + std::list::iterator it_for_row_ensure_single_line_block(int row); + std::list::iterator split_out_row_from_block(std::list::iterator block_it, int row_in_block); + void push_at_most_to_scrollback(int lines); + void reclaim_at_least(int lines); + void remove_lines_from_end(int lines); + void ensure_at_least_height(int height); + int content_height_diff(size_t old_content_height); + Screen *m_screen; + Scrollback *m_scrollback; + int m_screen_height; + int m_height; + int m_width; + int m_block_count; + int m_old_total_lines; + + std::list m_screen_blocks; +}; + +std::list::iterator ScreenData::it_for_row(int row) +{ + if (row >= m_screen_height) { + return m_screen_blocks.end(); + } + auto it = m_screen_blocks.end(); + int line_for_block = m_screen_height; + size_t abs_line = contentHeight(); + while (it != m_screen_blocks.begin()) { + --it; + line_for_block -= (*it)->lineCount(); + abs_line -= (*it)->lineCount(); + if (line_for_block <= row) { + (*it)->setScreenIndex(line_for_block); + (*it)->setLine(abs_line); + return it; + } + } + + return m_screen_blocks.end(); +} +#endif // SCREENDATA_H diff --git a/yat/backend/scrollback.cpp b/yat/backend/scrollback.cpp new file mode 100644 index 0000000..7463604 --- /dev/null +++ b/yat/backend/scrollback.cpp @@ -0,0 +1,215 @@ +/****************************************************************************** +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +******************************************************************************/ + +#include "scrollback.h" + +#include "screen_data.h" +#include "screen.h" +#include "block.h" + +#define P_VAR(variable) \ + #variable ":" << variable + +Scrollback::Scrollback(size_t max_size, ScreenData *screen_data) + : m_screen_data(screen_data) + , m_height(0) + , m_width(0) + , m_block_count(0) + , m_max_size(max_size) + , m_adjust_visible_pages(0) +{ +} + +void Scrollback::addBlock(Block *block) +{ + if (!m_max_size) { + delete block; + return; + } + + m_blocks.push_back(block); + block->releaseTextObjects(); + m_block_count++; + m_height += m_blocks.back()->lineCount(); + + while (m_height - m_blocks.front()->lineCount() >= m_max_size) { + m_block_count--; + m_height -= m_blocks.front()->lineCount(); + delete m_blocks.front(); + m_blocks.pop_front(); + m_adjust_visible_pages++; + } + + m_visible_pages.clear(); +} + +Block *Scrollback::reclaimBlock() +{ + if (m_blocks.empty()) + return nullptr; + + Block *last = m_blocks.back(); + last->setWidth(m_width); + m_block_count--; + m_height -= last->lineCount(); + m_blocks.pop_back(); + + m_visible_pages.clear(); + return last; +} + +void Scrollback::ensureVisiblePages(int top_line) +{ + if (top_line < 0) + return; + if (size_t(top_line) >= m_height) + return; + + uint height = std::max(m_screen_data->screen()->height(), 1); + + int complete_pages = m_height / height; + int remainder = m_height - (complete_pages * height); + + int top_page = top_line / height; + int bottom_page = top_page + 1; + + std::set pages_to_update; + pages_to_update.insert(top_page); + if (bottom_page * height < m_height) + pages_to_update.insert(bottom_page); + + for (auto it = m_visible_pages.begin(); it != m_visible_pages.end(); ++it) { + Page &page = *it; + if (pages_to_update.count(page.page_no) != 0) { + if (page.page_no < complete_pages) { + ensurePageVisible(page, height); + } else if (page.page_no == complete_pages) { + ensurePageVisible(page, remainder); + } + pages_to_update.erase(page.page_no); + } else { + ensurePageNotVisible(page); + auto to_remove = it; + --it; + m_visible_pages.erase(to_remove); + } + } + + for (auto it = pages_to_update.begin(); it != pages_to_update.end(); ++it) { + auto page_it = findIteratorForPage(*it); + m_visible_pages.push_back( { *it, 0, page_it } ); + if (*it < complete_pages) { + ensurePageVisible(m_visible_pages.back(), height); + } else if (*it == complete_pages) { + ensurePageVisible(m_visible_pages.back(), remainder); + } + } +} + +void Scrollback::ensurePageVisible(Page &page, int new_height) +{ + if (page.size == new_height || !m_block_count) + return; + + int line_no = page.page_no * m_screen_data->screen()->height(); + auto it = page.it; + std::advance(it, page.size); + for (int i = page.size; i < new_height; ++it, i++) { + (*it)->setLine(line_no + i); + (*it)->dispatchEvents(); + } + page.size = new_height; +} + +void Scrollback::ensurePageNotVisible(Page &page) +{ + auto it = page.it; + for (int i = 0; i < page.size; ++it, i++) { + (*it)->releaseTextObjects(); + } + page.size = 0; +} + +std::list::iterator Scrollback::findIteratorForPage(int page_no) +{ + uint line = page_no * m_screen_data->screen()->height(); + Q_ASSERT(line < m_height); + for (auto it = m_visible_pages.begin(); it != m_visible_pages.end(); ++it) { + Page &page = *it; + int diff = page_no - page.page_no; + if (diff < 5 && diff > 5) { + auto to_return = page.it; + int advance = diff * m_screen_data->screen()->height(); + std::advance(to_return, advance); + return to_return; + } + } + + if (line > m_height / 2) { + auto to_return = m_blocks.end(); + std::advance(to_return, line - m_height); + return to_return; + } + + auto to_return = m_blocks.begin(); + std::advance(to_return, line); + return to_return; +} + +void Scrollback::adjustVisiblePages() +{ + if (!m_adjust_visible_pages) + return; + + for (auto it = m_visible_pages.begin(); it != m_visible_pages.end(); ++it) { + Page &page = *it; + const size_t line_for_page = page.page_no * m_screen_data->screen()->height(); + if (line_for_page < m_adjust_visible_pages) { + auto to_remove = it; + --it; + m_visible_pages.erase(to_remove); + } else { + page.size = 0; + std::advance(page.it, m_adjust_visible_pages); + } + } + + m_adjust_visible_pages = 0; +} + +size_t Scrollback::height() const +{ + return m_height; +} + +void Scrollback::setWidth(int width) +{ + m_width = width; +} + +QString Scrollback::selection(const QPoint &start, const QPoint &end) const +{ + Q_UNUSED(start); + Q_UNUSED(end); + return QString(); +} diff --git a/yat/backend/scrollback.h b/yat/backend/scrollback.h new file mode 100644 index 0000000..f5b73c9 --- /dev/null +++ b/yat/backend/scrollback.h @@ -0,0 +1,73 @@ +/****************************************************************************** +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +******************************************************************************/ + +#ifndef SCROLLBACK_H +#define SCROLLBACK_H + +#include +#include + +#include +#include +class ScreenData; +class Block; + +struct Page { + int page_no; + int size; + std::list::iterator it; +}; + +class Scrollback +{ +public: + Scrollback(size_t max_size, ScreenData *screen_data); + + void addBlock(Block *block); + Block *reclaimBlock(); + void ensureVisiblePages(int top_line); + + size_t height() const; + + void setWidth(int width); + + size_t blockCount() { return m_block_count; } + + QString selection(const QPoint &start, const QPoint &end) const; +private: + void ensurePageVisible(Page &page, int new_height); + void ensurePageNotVisible(Page &page); + std::list::iterator findIteratorForPage(int page_no); + void adjustVisiblePages(); + ScreenData *m_screen_data; + + std::list m_blocks; + std::list m_visible_pages; + size_t m_height; + size_t m_width; + size_t m_block_count; + size_t m_max_size; + size_t m_adjust_visible_pages; +}; + +#endif //SCROLLBACK_H diff --git a/yat/backend/selection.cpp b/yat/backend/selection.cpp new file mode 100644 index 0000000..fbf754e --- /dev/null +++ b/yat/backend/selection.cpp @@ -0,0 +1,197 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#include "selection.h" + +#include "screen.h" +#include "screen_data.h" + +#include + +Selection::Selection(Screen *screen) + : QObject(screen) + , m_screen(screen) + , m_new_start_x(0) + , m_start_x(0) + , m_new_start_y(0) + , m_start_y(0) + , m_new_end_x(0) + , m_end_x(0) + , m_new_end_y(0) + , m_end_y(0) + , m_new_enable(false) +{ + connect(screen, &Screen::contentModified, this, &Selection::screenContentModified); + +} + +void Selection::setStartX(int x) +{ + if (x != m_new_start_x) { + m_new_start_x = x; + setValidity(); + m_screen->scheduleEventDispatch(); + } +} + +int Selection::startX() const +{ + return m_start_x; +} + +void Selection::setStartY(int y) +{ + if (y != m_new_start_y) { + m_new_start_y = y; + setValidity(); + m_screen->scheduleEventDispatch(); + } +} + +int Selection::startY() const +{ + return m_start_y; +} + +void Selection::setEndX(int x) +{ + if (m_new_end_x != x) { + m_new_end_x = x; + setValidity(); + m_screen->scheduleEventDispatch(); + } +} + +int Selection::endX() const +{ + return m_end_x; +} + +void Selection::setEndY(int y) +{ + if (m_new_end_y != y) { + m_new_end_y = y; + setValidity(); + m_screen->scheduleEventDispatch(); + } +} + +int Selection::endY() const +{ + return m_end_y; +} + +void Selection::setEnable(bool enable) +{ + if (m_new_enable != enable) { + m_new_enable = enable; + m_screen->scheduleEventDispatch(); + } +} + +void Selection::screenContentModified(size_t lineModified, int lineDiff, int contentDiff) +{ + if (!m_new_enable) + return; + + if (lineModified >= size_t(m_new_start_y) && lineModified <= size_t(m_new_end_y)) { + setEnable(false); + return; + } + + if (size_t(m_new_end_y) < lineModified && lineModified != contentDiff) { + m_new_end_y -= lineDiff - contentDiff; + m_new_start_y -= lineDiff - contentDiff; + if (m_new_end_y < 0) { + setEnable(false); + return; + } + if (m_new_start_y < 0) { + m_new_start_y = 0; + } + m_screen->scheduleEventDispatch(); + } +} + +void Selection::setValidity() +{ + if (m_new_end_y > m_new_start_y || + (m_new_end_y == m_new_start_y && + m_new_end_x > m_new_start_x)) { + setEnable(true); + } else { + setEnable(false); + } +} + +void Selection::sendToClipboard() const +{ + m_screen->currentScreenData()->sendSelectionToClipboard(start_new_point(), end_new_point(), QClipboard::Clipboard); +} + +void Selection::sendToSelection() const +{ + m_screen->currentScreenData()->sendSelectionToClipboard(start_new_point(), end_new_point(), QClipboard::Selection); +} + +void Selection::pasteFromSelection() +{ + m_screen->pty()->write(QGuiApplication::clipboard()->text(QClipboard::Selection).toUtf8()); +} + +void Selection::pasteFromClipboard() +{ + m_screen->pty()->write(QGuiApplication::clipboard()->text(QClipboard::Clipboard).toUtf8()); +} + +void Selection::dispatchChanges() +{ + if (!m_new_enable && !m_enable) + return; + + if (m_new_start_y != m_start_y) { + m_start_y = m_new_start_y; + emit startYChanged(); + } + if (m_new_start_x != m_start_x) { + m_start_x = m_new_start_x; + emit startXChanged(); + } + if (m_new_end_y != m_end_y) { + m_end_y = m_new_end_y; + emit endYChanged(); + } + if (m_new_end_x != m_end_x) { + m_end_x = m_new_end_x; + emit endXChanged(); + } + if (m_new_enable != m_enable) { + m_enable = m_new_enable; + emit enableChanged(); + } +} + +bool Selection::enable() const +{ + return m_enable; +} diff --git a/yat/backend/selection.h b/yat/backend/selection.h new file mode 100644 index 0000000..b16716c --- /dev/null +++ b/yat/backend/selection.h @@ -0,0 +1,93 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#ifndef SELECTION_H +#define SELECTION_H + +#include +#include + +class Screen; + +class Selection : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int startX READ startX WRITE setStartX NOTIFY startXChanged) + Q_PROPERTY(int startY READ startY WRITE setStartY NOTIFY startYChanged) + Q_PROPERTY(int endX READ endX WRITE setEndX NOTIFY endXChanged) + Q_PROPERTY(int endY READ endY WRITE setEndY NOTIFY endYChanged) + Q_PROPERTY(bool enable READ enable WRITE setEnable NOTIFY enableChanged) + +public: + explicit Selection(Screen *screen); + + void setStartX(int x); + int startX() const; + + void setStartY(int y); + int startY() const; + + void setEndX(int x); + int endX() const; + + void setEndY(int y); + int endY() const; + + void setEnable(bool enabled); + bool enable() const; + + Q_INVOKABLE void sendToClipboard() const; + Q_INVOKABLE void sendToSelection() const; + Q_INVOKABLE void pasteFromSelection(); + Q_INVOKABLE void pasteFromClipboard(); + + void dispatchChanges(); +signals: + void startXChanged(); + void startYChanged(); + void endXChanged(); + void endYChanged(); + void enableChanged(); + +private slots: + void screenContentModified(size_t lineModified, int lineDiff, int contentDiff); + +private: + void setValidity(); + QPoint start_new_point() const { return QPoint(m_new_start_x, m_new_start_y); } + QPoint end_new_point() const { return QPoint(m_new_end_x, m_new_end_y); } + + Screen *m_screen; + int m_new_start_x; + int m_start_x; + int m_new_start_y; + int m_start_y; + int m_new_end_x; + int m_end_x; + int m_new_end_y; + int m_end_y; + bool m_new_enable; + bool m_enable; +}; +#endif diff --git a/yat/backend/text.cpp b/yat/backend/text.cpp new file mode 100644 index 0000000..4d2247e --- /dev/null +++ b/yat/backend/text.cpp @@ -0,0 +1,255 @@ +/************************************************************************************************** +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +* associated documentation files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, publish, distribute, +* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +* OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +***************************************************************************************************/ + +#include "text.h" + +#include "screen.h" +#include "block.h" +#include + +#include + +Text::Text(Screen *screen) + : QObject(screen) + , m_screen(screen) + , m_text_line(0) + , m_start_index(0) + , m_old_start_index(0) + , m_end_index(0) + , m_line(0) + , m_old_line(0) + , m_width(1) + , m_style_dirty(true) + , m_text_dirty(true) + , m_visible(true) + , m_visible_old(true) + , m_latin(true) + , m_latin_old(true) + , m_forgroundColor(m_screen->defaultForgroundColor()) + , m_backgroundColor(m_screen->defaultBackgroundColor()) +{ + connect(m_screen->colorPalette(), SIGNAL(changed()), this, SLOT(paletteChanged())); + connect(m_screen, SIGNAL(dispatchTextSegmentChanges()), this, SLOT(dispatchEvents())); +} + +Text::~Text() +{ +} + +int Text::index() const +{ + return m_start_index % m_width; +} + +int Text::line() const +{ + return m_line + (m_start_index / m_width); +} + +void Text::setLine(int line, int width, const QString *textLine) +{ + m_line = line; + m_width = width; + m_text_dirty = true; + m_text_line = textLine; +} + +bool Text::visible() const +{ + return m_visible; +} + +void Text::setVisible(bool visible) +{ + m_visible = visible; +} + +QString Text::text() const +{ + return m_text; +} + +QColor Text::foregroundColor() const +{ + return m_forgroundColor; +} + + +QColor Text::backgroundColor() const +{ + return m_backgroundColor; +} + +void Text::setStringSegment(int start_index, int end_index, bool text_changed) +{ + m_start_index = start_index; + m_end_index = end_index; + + m_text_dirty = text_changed; +} + +void Text::setTextStyle(const TextStyle &style) +{ + m_new_style = style; + m_style_dirty = true; +} + +bool Text::bold() const +{ + return m_style.style & TextStyle::Bold; +} + +bool Text::blinking() const +{ + return m_style.style & TextStyle::Blinking; +} + +bool Text::underline() const +{ + return m_style.style & TextStyle::Underlined; +} + +void Text::setLatin(bool latin) +{ + m_latin = latin; +} + +bool Text::latin() const +{ + return m_latin_old; +} + +static bool differentStyle(TextStyle::Styles a, TextStyle::Styles b, TextStyle::Style style) +{ + return (a & style) != (b & style); +} + +void Text::dispatchEvents() +{ + int old_line = m_old_line + (m_old_start_index / m_width); + int new_line = m_line + (m_start_index / m_width); + if (old_line != new_line) { + m_old_line = m_line; + emit lineChanged(); + } + + if (m_latin != m_latin_old) { + m_latin_old = m_latin; + emit latinChanged(); + } + + if (m_old_start_index != m_start_index + || m_text_dirty) { + m_text_dirty = false; + QString old_text = m_text; + m_text = m_text_line->mid(m_start_index, m_end_index - m_start_index + 1); + if (m_old_start_index != m_start_index) { + m_old_start_index = m_start_index; + emit indexChanged(); + } + emit textChanged(); + } + + if (m_style_dirty) { + m_style_dirty = false; + + bool emit_forground = m_new_style.forground != m_style.forground; + bool emit_background = m_new_style.background != m_style.background; + TextStyle::Styles new_style = m_new_style.style; + TextStyle::Styles old_style = m_style.style; + + bool emit_bold = false; + bool emit_blink = false; + bool emit_underline = false; + bool emit_inverse = false; + if (new_style != old_style) { + emit_bold = differentStyle(new_style, old_style, TextStyle::Bold); + emit_blink = differentStyle(new_style, old_style, TextStyle::Blinking); + emit_underline = differentStyle(new_style, old_style, TextStyle::Underlined); + emit_inverse = differentStyle(new_style, old_style, TextStyle::Inverse); + } + + m_style = m_new_style; + if (emit_inverse) { + setForgroundColor(); + setBackgroundColor(); + } else { + if (emit_forground || emit_bold) { + setForgroundColor(); + } + if (emit_background) { + setBackgroundColor(); + } + } + + if (emit_bold) { + emit boldChanged(); + } + + if (emit_blink) { + emit blinkingChanged(); + } + + if (emit_underline) { + emit underlineChanged(); + } + + } + + + if (m_visible_old != m_visible) { + m_visible_old = m_visible; + emit visibleChanged(); + } +} + +void Text::paletteChanged() +{ + setBackgroundColor(); + setForgroundColor(); +} + +void Text::setBackgroundColor() +{ + QColor new_background; + if (m_style.style & TextStyle::Inverse) { + new_background = m_screen->colorPalette()->color(m_style.forground, false); + } else { + new_background = m_screen->colorPalette()->color(m_style.background, false); + } + if (new_background != m_backgroundColor) { + m_backgroundColor = new_background; + emit backgroundColorChanged(); + } +} + +void Text::setForgroundColor() +{ + QColor new_forground; + if (m_style.style & TextStyle::Inverse) { + new_forground = m_screen->colorPalette()->color(m_style.background, false); + } else { + new_forground = m_screen->colorPalette()->color(m_style.forground, false); + } + if (new_forground != m_forgroundColor) { + m_forgroundColor = new_forground; + emit forgroundColorChanged(); + } +} diff --git a/yat/backend/text.h b/yat/backend/text.h new file mode 100644 index 0000000..79dd82f --- /dev/null +++ b/yat/backend/text.h @@ -0,0 +1,121 @@ +/************************************************************************************************** +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +* associated documentation files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, publish, distribute, +* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +* OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +***************************************************************************************************/ + +#ifndef TEXT_SEGMENT_H +#define TEXT_SEGMENT_H + +#include +#include +#include +#include + +#include "text_style.h" + +class Screen; +class QQuickItem; + +class Text : public QObject +{ + Q_OBJECT + Q_PROPERTY(int index READ index NOTIFY indexChanged) + Q_PROPERTY(int line READ line NOTIFY lineChanged) + Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged) + Q_PROPERTY(QString text READ text NOTIFY textChanged) + Q_PROPERTY(QColor foregroundColor READ foregroundColor NOTIFY forgroundColorChanged) + Q_PROPERTY(QColor backgroundColor READ backgroundColor NOTIFY backgroundColorChanged) + Q_PROPERTY(bool bold READ bold NOTIFY boldChanged) + Q_PROPERTY(bool blinking READ blinking NOTIFY blinkingChanged) + Q_PROPERTY(bool underline READ underline NOTIFY underlineChanged) + Q_PROPERTY(bool latin READ latin NOTIFY latinChanged) +public: + Text(Screen *screen); + ~Text(); + + int index() const; + + int line() const; + void setLine(int line, int width, const QString *textLine); + + bool visible() const; + void setVisible(bool visible); + + QString text() const; + QColor foregroundColor() const; + QColor backgroundColor() const; + + void setStringSegment(int start_index, int end_index, bool textChanged); + void setTextStyle(const TextStyle &style); + + bool bold() const; + bool blinking() const; + bool underline() const; + + void setLatin(bool latin); + bool latin() const; + + QObject *item() const; + +public slots: + void dispatchEvents(); + +signals: + void indexChanged(); + void lineChanged(); + void visibleChanged(); + void textChanged(); + void forgroundColorChanged(); + void backgroundColorChanged(); + void boldChanged(); + void blinkingChanged(); + void underlineChanged(); + void latinChanged(); + +private slots: + void paletteChanged(); + +private: + void setBackgroundColor(); + void setForgroundColor(); + + Screen *m_screen; + QString m_text; + const QString *m_text_line; + int m_start_index; + int m_old_start_index; + int m_end_index; + int m_line; + int m_old_line; + int m_width; + + TextStyle m_style; + TextStyle m_new_style; + + bool m_style_dirty; + bool m_text_dirty; + bool m_visible; + bool m_visible_old; + bool m_latin; + bool m_latin_old; + + QColor m_forgroundColor; + QColor m_backgroundColor; +}; + +#endif // TEXT_SEGMENT_H diff --git a/yat/backend/text_style.cpp b/yat/backend/text_style.cpp new file mode 100644 index 0000000..a95dd08 --- /dev/null +++ b/yat/backend/text_style.cpp @@ -0,0 +1,36 @@ +#include "text_style.h" + +#include "screen.h" +#include "text.h" + +#include + +TextStyle::TextStyle() + : style(Normal) + , forground(ColorPalette::DefaultForground) + , background(ColorPalette::DefaultBackground) +{ + +} + +bool TextStyle::isCompatible(const TextStyle &other) const +{ + return forground == other.forground + && background == other.background + && style == other.style; +} + +QDebug operator<<(QDebug debug, TextStyleLine line) +{ + debug << "[" << line.start_index << "(" << line.style << ":" << line.forground << ":" << line.background << ")" << line.end_index << "]"; + return debug; +} + +void TextStyleLine::releaseTextSegment(Screen *screen) +{ + if (text_segment) { + text_segment->setVisible(false); + screen->releaseTextSegment(text_segment); + text_segment = 0; + } +} diff --git a/yat/backend/text_style.h b/yat/backend/text_style.h new file mode 100644 index 0000000..a24fc69 --- /dev/null +++ b/yat/backend/text_style.h @@ -0,0 +1,85 @@ +#ifndef TEXT_STYLE_H +#define TEXT_STYLE_H + +#include + +#include "color_palette.h" + +class Screen; + +class TextStyle +{ +public: + enum Style { + Normal = 0x0000, + Italic = 0x0001, + Bold = 0x0002, + Underlined = 0x0004, + Blinking = 0x0008, + FastBlinking = 0x0010, + Gothic = 0x0020, + DoubleUnderlined = 0x0040, + Framed = 0x0080, + Overlined = 0x0100, + Encircled = 0x0200, + Inverse = 0x0400 + }; + Q_DECLARE_FLAGS(Styles, Style) + + TextStyle(); + + Styles style; + ColorPalette::Color forground; + ColorPalette::Color background; + + bool isCompatible(const TextStyle &other) const; +}; + +class Text; +class TextStyleLine : public TextStyle { +public: + TextStyleLine(const TextStyle &style, int start_index, int end_index) + : TextStyle(style) + , start_index(start_index) + , end_index(end_index) + , old_index(-1) + , text_segment(0) + , style_dirty(true) + , index_dirty(true) + , text_dirty(true) + { + } + + TextStyleLine() + : start_index(0) + , end_index(0) + , old_index(-1) + , text_segment(0) + , style_dirty(false) + , index_dirty(false) + , text_dirty(false) + { + + } + + void releaseTextSegment(Screen *screen); + + int start_index; + int end_index; + + int old_index; + Text *text_segment; + bool style_dirty; + bool index_dirty; + bool text_dirty; + + void setStyle(const TextStyle &style) { + forground = style.forground; + background = style.background; + this->style = style.style; + } +}; +QDebug operator<<(QDebug debug, TextStyleLine line); + + +#endif // TEXT_STYLE_H diff --git a/yat/backend/utf8_decoder.h b/yat/backend/utf8_decoder.h new file mode 100644 index 0000000..62271b0 --- /dev/null +++ b/yat/backend/utf8_decoder.h @@ -0,0 +1,109 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#ifndef UTF8_DECODER +#define UTF8_DECODER + +#include "controll_chars.h" + +class Utf8Decoder +{ +public: + inline Utf8Decoder(); + + inline void addChar(uchar character); + + inline bool isLatin() const; + inline bool isC1() const; + + inline void clear(); +private: + short m_expected_length; + short m_length; + uint32_t m_unicode; +}; + +Utf8Decoder::Utf8Decoder() +{ + clear(); +} + +void Utf8Decoder::addChar(uchar character) +{ + if (m_length && m_length == m_expected_length) { + clear(); + } + + if (character < 0x80) + return; + + fprintf(stderr, "Character: 0x%x\n", character); + if (m_expected_length == 0) { + //this is naive. There must be a faster way. + if ((character & 0xfc) == 0xfc) { + m_expected_length = 5; + m_unicode = character & 0x01; + } else if ((character & 0xf8) == 0xf8) { + m_expected_length = 4; + m_unicode = character & 0x03; + } else if ((character & 0xf0) == 0xf0) { + m_expected_length = 3; + m_unicode = character & 0x07; + } else if ((character & 0xe0) == 0xe0) { + m_expected_length = 2; + m_unicode = character & 0x0f; + } else if ((character & 0xc0) == 0xc0) { + m_expected_length = 1; + m_unicode = character & 0x1f; + } else { + m_expected_length = 0; + m_unicode = 0; + qWarning("Utf8Decoder: invalid decoder character"); + } + } else { + fprintf(stderr, "Before 0x%x adding 0x%x pure 0x%x\n", m_unicode,(character & 0x3f), character); + m_unicode = (m_unicode << 6) | (character & 0x3f); + fprintf(stderr, "After 0x%x\n", m_unicode); + m_length++; + } +} + +bool Utf8Decoder::isLatin() const +{ + return m_expected_length < 2 && m_unicode < 0xff; +} + +bool Utf8Decoder::isC1() const +{ + return m_expected_length == 2 && m_length == m_expected_length && + (m_unicode >= C1_8bit::C1_8bit_Start && m_unicode <= C1_8bit::C1_8bit_Stop); +} + +void Utf8Decoder::clear() +{ + m_expected_length = 0; + m_length = 0; + m_unicode = 0; +} + +#endif diff --git a/yat/backend/yat_pty.cpp b/yat/backend/yat_pty.cpp new file mode 100644 index 0000000..e14a82a --- /dev/null +++ b/yat/backend/yat_pty.cpp @@ -0,0 +1,139 @@ +/************************************************************************************************** +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +* associated documentation files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, publish, distribute, +* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +* OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +***************************************************************************************************/ + +#include "yat_pty.h" + +#include +#include + +#ifdef LINUX +#include +#endif + +#include +#ifdef Q_OS_MAC +#include +#else +#include +#endif +#include + +#include +#include +#include +#include +#include + +static char env_variables[][255] = { + "TERM=xterm-color", + "COLORTERM=xterm", + "COLORFGBG=15;0", + "LINES", + "COLUMNS", + "TERMCAP" +}; +static int env_variables_size = sizeof(env_variables) / sizeof(env_variables[0]); + +YatPty::YatPty() + : m_winsize(0) +{ + m_terminal_pid = forkpty(&m_master_fd, + NULL, + NULL, + NULL); + + if (m_terminal_pid == 0) { + for (int i = 0; i < env_variables_size; i++) { + ::putenv(env_variables[i]); + } + ::execl("/bin/bash", "/bin/bash", "--login", (const char *) 0); + exit(0); + } + + QSocketNotifier *reader = new QSocketNotifier(m_master_fd,QSocketNotifier::Read,this); + connect(reader, &QSocketNotifier::activated, this, &YatPty::readData); +} + +YatPty::~YatPty() +{ +} + +void YatPty::write(const QByteArray &data) +{ + if (::write(m_master_fd, data.constData(), data.size()) < 0) { + qDebug() << "Something whent wrong when writing to m_master_fd"; + } +} + +void YatPty::setWidth(int width, int pixelWidth) +{ + if (!m_winsize) { + m_winsize = new struct winsize; + m_winsize->ws_row = 25; + m_winsize->ws_ypixel = 0; + } + + m_winsize->ws_col = width; + m_winsize->ws_xpixel = pixelWidth; + ioctl(m_master_fd, TIOCSWINSZ, m_winsize); +} + +void YatPty::setHeight(int height, int pixelHeight) +{ + if (!m_winsize) { + m_winsize = new struct winsize; + m_winsize->ws_col = 80; + m_winsize->ws_xpixel = 0; + } + m_winsize->ws_row = height; + m_winsize->ws_ypixel = pixelHeight; + ioctl(m_master_fd, TIOCSWINSZ, m_winsize); + +} + +QSize YatPty::size() const +{ + if (!m_winsize) { + YatPty *that = const_cast(this); + that->m_winsize = new struct winsize; + ioctl(m_master_fd, TIOCGWINSZ, m_winsize); + } + return QSize(m_winsize->ws_col, m_winsize->ws_row); +} + +int YatPty::masterDevice() const +{ + return m_master_fd; +} + + +void YatPty::readData() +{ + int size_of_buffer = sizeof m_data_buffer / sizeof *m_data_buffer; + ssize_t read_size = ::read(m_master_fd,m_data_buffer,size_of_buffer); + if (read_size > 0) { + QByteArray to_return = QByteArray::fromRawData(m_data_buffer,read_size); + emit readyRead(to_return); + } else if (read_size < 0) { + emit hangupReceived(); + } else { + emit hangupReceived(); + } +} diff --git a/yat/backend/yat_pty.h b/yat/backend/yat_pty.h new file mode 100644 index 0000000..b14ada2 --- /dev/null +++ b/yat/backend/yat_pty.h @@ -0,0 +1,59 @@ +/************************************************************************************************** +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +* associated documentation files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, publish, distribute, +* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +* OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +***************************************************************************************************/ + +#ifndef YAT_PTY_H +#define YAT_PTY_H + +#include + +#include +#include +#include + +class YatPty : public QObject +{ + Q_OBJECT +public: + YatPty(); + ~YatPty(); + + void write(const QByteArray &data); + + void setWidth(int width, int pixelWidth = 0); + void setHeight(int height, int pixelHeight = 0); + QSize size() const; + + int masterDevice() const; + +signals: + void hangupReceived(); + void readyRead(const QByteArray &data); + +private: + void readData(); + + pid_t m_terminal_pid; + int m_master_fd; + char m_slave_file_name[PATH_MAX]; + struct winsize *m_winsize; + char m_data_buffer[1024]; +}; + +#endif //YAT_PTY_H diff --git a/yat/docs/Ecma-048.pdf b/yat/docs/Ecma-048.pdf new file mode 100644 index 0000000..e1441c5 Binary files /dev/null and b/yat/docs/Ecma-048.pdf differ diff --git a/yat/docs/Xterm Control Sequences.html b/yat/docs/Xterm Control Sequences.html new file mode 100644 index 0000000..cf3453c --- /dev/null +++ b/yat/docs/Xterm Control Sequences.html @@ -0,0 +1,4841 @@ + + + + + + + + + +Xterm Control Sequences + + + + +

Xterm Control Sequences

+ +Definitions
+C1 (8-Bit) Control Characters
+VT100 Mode
+Alt and Meta Keys
+PC-Style Function Keys
+VT220-Style Function Keys
+VT52-Style Function Keys
+Sun-Style Function Keys
+HP-Style Function Keys
+The Alternate Screen Buffer
+Bracketed Paste Mode
+Title Modes
+Mouse Tracking
+Tektronix 4014 Mode
+VT52 Mode
+ +
+ + +

Edward Moy
+University of California, Berkeley

+ + +

Revised +by
+Stephen Gildea

+X Consortium (1994)
+Thomas Dickey

+XFree86 Project (1996-2006)
+invisible-island.net (2006-2012)

+ + +

Definitions

+ + + + + + + + + + + + + + + + + + + + + + + +
+ + +

c

+ + +

The literal +character c.

+ + +

C

+ + +

A single (required) +character.

+ + +

P +s

+ + +

A single (usually +optional) numeric parameter, composed of one of more +digits.

+ + +

P +m

+ + +

A multiple numeric +parameter composed of any number of single numeric +parameters, separated by ; character(s). Individual values +for the parameters are listed with P s +.

+ + +

P +t

+ + +

A text parameter +composed of printable characters.

+ + +

C1 (8-Bit) Control Characters

+ + +

The xterm +program recognizes both 8-bit and 7-bit control characters. +It generates 7-bit controls (by default) or 8-bit if S8C1T +is enabled. The following pairs of 7-bit and 8-bit control +characters are equivalent:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +

ESC +D

+ + +

Index ( +IND is 0x84).

+ + +

ESC E

+ + +

Next Line ( +NEL is 0x85).

+ + +

ESC H

+ + +

Tab Set ( HTS +is 0x88).

+ + +

ESC M

+ + +

Reverse Index ( +RI is 0x8d).

+ + +

ESC N

+ + +

Single Shift Select of G2 Character Set ( +SS2 is 0x8e). This affects +next character only.

+ + +

ESC O

+ + +

Single Shift Select of G3 Character Set ( +SS3 is 0x8f). This affects +next character only.

+ + +

ESC P

+ + +

Device Control String ( +DCS is 0x90).

+ + +

ESC V

+ + +

Start of Guarded Area ( +SPA is 0x96).

+ + +

ESC W

+ + +

End of Guarded Area ( +EPA is 0x97).

+ + +

ESC X

+ + +

Start of String ( +SOS is 0x98).

+ + +

ESC Z

+ + +

Return Terminal ID (DECID is 0x9a). +Obsolete form of CSI c +(DA).

+ + +

ESC [

+ + +

Control Sequence Introducer ( +CSI is 0x9b).

+ + +

ESC \

+ + +

String Terminator ( +ST is 0x9c).

+ + +

ESC ]

+ + +

Operating System Command ( +OSC is 0x9d).

+ + +

ESC ^

+ + +

Privacy Message ( +PM is 0x9e).

+ + +

ESC _

+ + +

Application Program Command ( +APC is 0x9f).

+ +

These control +characters are used in the vtXXX emulation.

+ + +

VT100 Mode

+ + +

Most of these +control sequences are standard VT102 control sequences, but +there is support for later DEC VT terminals (i.e., VT220, +VT320, VT420, VT510), as well as ISO 6429 and aixterm +color controls. The only VT102 feature not supported is +auto-repeat, since the only way X provides for this will +affect all windows. There are additional control sequences +to provide xterm-dependent functions, such as the +scrollbar or window size. Where the function is specified by +DEC or ISO 6429, the code assigned to it is given in +parentheses. The escape codes to designate and invoke +character sets are specified by ISO 2022; see that document +for a discussion of character sets.

+ + +

Single-character +functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

BEL

+ + +

Bell (Ctrl-G).

+ + +

BS

+ + +

Backspace (Ctrl-H).

+ + +

CR

+ + +

Carriage Return (Ctrl-M).

+ + +

ENQ

+ + +

Return Terminal Status (Ctrl-E). Default +response is an empty string, but may be overridden by a +resource answerbackString.

+ + +

FF

+ + +

Form Feed or New Page (NP). Ctrl-L is +treated the same as LF.

+ + +

LF

+ + +

Line Feed or New Line (NL). (LF is +Ctrl-J).

+ + +

SI

+ + +

Shift In (Ctrl-O) → Switch to Standard +Character Set. This invokes the G0 character set (the +default).

+ + +

SO

+ + +

Shift Out (Ctrl-N) → Switch to +Alternate Character Set. This invokes the G1 character +set.

+ + +

SP

+ + +

Space.

+ + +

TAB

+ + +

Horizontal Tab (HT) (Ctrl-I).

+ + +

VT

+ + +

Vertical Tab (Ctrl-K). This is treated the +same as LF.

+ +

Controls +beginning with ESC
+This excludes controls where +ESC is part of a 7-bit +equivalent to 8-bit C1 controls, ordered by the final +character(s).

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

ESC SP F

+ + +

7-bit controls (S7C1T).

+ + +

ESC SP G

+ + +

8-bit controls (S8C1T).

+ + +

ESC SP L

+ + +

Set ANSI conformance level 1 (dpANS +X3.134.1).

+ + +

ESC SP M

+ + +

Set ANSI conformance level 2 (dpANS +X3.134.1).

+ + +

ESC SP N

+ + +

Set ANSI conformance level 3 (dpANS +X3.134.1).

+ + +

ESC # 3

+ + +

DEC double-height line, top half +(DECDHL).

+ + +

ESC # 4

+ + +

DEC double-height line, bottom half +(DECDHL).

+ + +

ESC # 5

+ + +

DEC single-width line (DECSWL).

+ + +

ESC # 6

+ + +

DEC double-width line (DECDWL).

+ + +

ESC # 8

+ + +

DEC Screen Alignment Test (DECALN).

+ + +

ESC % @

+ + +

Select default character set. That is ISO +8859-1 (ISO 2022).

+ + +

ESC % G

+ + +

Select UTF-8 character set (ISO 2022).

+ + +

ESC ( +C

+ + +

Designate G0 Character Set (ISO 2022, +VT100).

+ +

Final character C for +designating 94-character sets. In this list, 0 , A and B +apply to VT100 and up, the remainder to VT220 and up: +
+C
= 0 → DEC Special Character and Line Drawing Set. +
+C
= A → United Kingdom (UK).
+C
= B → United States (USASCII).
+C
= 4 → Dutch.
+C
= C or 5 → Finnish.
+C
= R → French.
+C
= Q → French Canadian.
+C
= K → German.
+C
= Y → Italian.
+C
= E or 6 → Norwegian/Danish.
+C
= Z → Spanish.
+C
= H or 7 → Swedish.
+C
= = → Swiss.

+ + + + + + + +
+ + +

ESC ) +C

+ + +

Designate G1 Character Set (ISO 2022, +VT100).

+
+ +

The same character sets apply +as for ESC ( C.

+ + + + + + + +
+ + +

ESC * +C

+ + +

Designate G2 Character Set (ISO 2022, +VT220).

+
+ +

The same character sets apply +as for ESC ( C.

+ + + + + + + +
+ + +

ESC + +C

+ + +

Designate G3 Character Set (ISO 2022, +VT220).

+
+ +

The same character sets apply +as for ESC ( C.

+ + + + + + + +
+ + +

ESC - +C

+ + +

Designate G1 Character Set (VT300).

+
+ +

The same character sets apply +as for ESC ( C.

+ + + + + + + +
+ + +

ESC . +C

+ + +

Designate G2 Character Set (VT300).

+
+ +

The same character sets apply +as for ESC ( C.

+ + + + + + + +
+ + +

ESC / +C

+ + +

Designate G3 Character Set (VT300).

+
+ +

These work for 96-character +sets only.
+C
= A → ISO Latin-1 Supplemental.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

ESC 6

+ + +

Back Index (DECBI), VT420 and up.

+ + +

ESC 7

+ + +

Save Cursor (DECSC).

+ + +

ESC 8

+ + +

Restore Cursor (DECRC).

+ + +

ESC 9

+ + +

Forward Index (DECFI), VT420 and up.

+ + +

ESC =

+ + +

Application Keypad (DECPAM).

+ + +

ESC >

+ + +

Normal Keypad (DECPNM).

+ + +

ESC F

+ + +

Cursor to lower left corner of screen. This +is enabled by the hpLowerleftBugCompat resource.

+ + +

ESC c

+ + +

Full Reset (RIS).

+ + +

ESC l

+ + +

Memory Lock (per HP terminals). Locks +memory above the cursor.

+ + +

ESC m

+ + +

Memory Unlock (per HP terminals).

+ + +

ESC n

+ + +

Invoke the G2 Character Set as GL +(LS2).

+ + +

ESC o

+ + +

Invoke the G3 Character Set as GL +(LS3).

+ + +

ESC |

+ + +

Invoke the G3 Character Set as GR +(LS3R).

+ + +

ESC }

+ + +

Invoke the G2 Character Set as GR +(LS2R).

+ + +

ESC ~

+ + +

Invoke the G1 Character Set as GR +(LS1R).

+ +

Application +Program-Control functions

+ + + + + + +
+ + +

APC P +t ST

+ + +

None. xterm implements no +APC functions; P +t is ignored. P t +need not be printable characters.

+ +

Device-Control +functions

+ + + + + +
+ + +

DCS P +s ; P s | P +t ST

+
+ +

User-Defined Keys (DECUDK). The +first parameter:
+P s
= 0 → Clear all UDK definitions +before starting (default).
+P s
= 1 → Erase Below (default). +
+The second parameter:
+P s
= 0 ← Lock the keys (default). +
+P s
= 1 ← Do not lock.
+The third parameter is a ’;’-separated list of +strings denoting the key-code separated by a ’/’ +from the hex-encoded key value. The key codes correspond to +the DEC function-key codes (e.g., F6=17).

+ + + + + +
+ + +

DCS $ q P +t ST

+
+ +

Request Status String +(DECRQSS). The string following the "q" is one of +the following:

+ + + + + +

“ q

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

→ DECSCA
+“ p

+ + +

→ DECSCL
+r

+
+ + +

→ DECSTBM
+m

+
+ + +

→ SGR
+SP
q

+ + +

→ DECSCUSR

+ +

xterm responds with +DCS 1 $ r P +t ST for +valid requests, replacing the P t with +the corresponding CSI string, +or DCS 0 $ r P +t ST for +invalid requests.

+ + + + + +
+ + +

DCS + p P +t ST

+
+ +

Set Termcap/Terminfo Data +(xterm, experimental). The string following the +"p" is a name to use for retrieving data from the +terminal database. The data will be used for the +"tcap" keyboard configuration’s function- +and special-keys, as well as by the Request Termcap/Terminfo +String control.

+ + + + + +
+ + +

DCS + q P +t ST

+
+ +

Request Termcap/Terminfo String +(xterm, experimental). The string following the +"q" is a list of names encoded in hexadecimal (2 +digits per character) separated by ; which correspond to +termcap or terminfo key names.
+Two special features are also recognized, which are not key +names: Co for termcap colors (or colors for +terminfo colors), and TN for termcap name (or +name for terminfo name).
+xterm
responds with DCS 1 ++ r P t +ST for valid requests, adding +to P t an = , and the value of the +corresponding string that xterm would send, or +DCS 0 + r P +t ST for +invalid requests. The strings are encoded in hexadecimal (2 +digits per character).

+ +

Functions using +CSI , ordered by the final +character(s)

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

CSI P +s @

+ + +

Insert P s (Blank) +Character(s) (default = 1) (ICH).

+ + +

CSI P +s A

+ + +

Cursor Up P s Times +(default = 1) (CUU).

+ + +

CSI P +s B

+ + +

Cursor Down P s Times +(default = 1) (CUD).

+ + +

CSI P +s C

+ + +

Cursor Forward P s +Times (default = 1) (CUF).

+ + +

CSI P +s D

+ + +

Cursor Backward P s +Times (default = 1) (CUB).

+ + +

CSI P +s E

+ + +

Cursor Next Line P s +Times (default = 1) (CNL).

+ + +

CSI P +s F

+ + +

Cursor Preceding Line P +s Times (default = 1) (CPL).

+ + +

CSI P +s G

+ + +

Cursor Character Absolute [column] (default += [row,1]) (CHA).

+ + +

CSI P +s ; P

+
+ +

s H

+ + + + + + + + + + + + + + +
+ + +

Cursor Position [row;column] (default = +[1,1]) (CUP).

+ + +

CSI P +s I

+ + +

Cursor Forward Tabulation P +s tab stops (default = 1) (CHT).

+ + +

CSI P +s J

+ + +

Erase in Display (ED).

+ +

P s = 0 +→ Erase Below (default).
+P s
= 1 → Erase Above.
+P s
= 2 → Erase All.
+P s
= 3 → Erase Saved Lines +(xterm).

+ + + + + + +
+ + +

CSI ? P +s J

+ + +

Erase in Display (DECSED).

+
+ +

P s = 0 +→ Selective Erase Below (default).
+P s
= 1 → Selective Erase Above. +
+P s
= 2 → Selective Erase All.

+ + + + + + + +
+ + +

CSI P +s K

+ + +

Erase in Line (EL).

+
+ +

P s = 0 +→ Erase to Right (default).
+P s
= 1 → Erase to Left.
+P s
= 2 → Erase All.

+ + + + + + +
+ + +

CSI ? P +s K

+ + +

Erase in Line (DECSEL).

+
+ +

P s = 0 +→ Selective Erase to Right (default).
+P s
= 1 → Selective Erase to Left. +
+P s
= 2 → Selective Erase All.

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

CSI P +s L

+ + +

Insert P s Line(s) +(default = 1) (IL).

+
+ + +

CSI P +s M

+ + +

Delete P s Line(s) +(default = 1) (DL).

+
+ + +

CSI P +s P

+ + +

Delete P s +Character(s) (default = 1) (DCH).

+
+ + +

CSI P +s S

+ + +

Scroll up P s lines +(default = 1) (SU).

+
+ + +

CSI P +s T

+ + +

Scroll down P s lines +(default = 1) (SD).

+
+ + +

CSI P +s ; P

+
+ +

s ; P +s ; P s ; P +s T

+ + + + + + + + + + +
+ + +

Initiate highlight mouse tracking. +Parameters are [func;startx;starty;firstrow;lastrow]. See +the section Mouse Tracking.

+ + +

CSI > P +s ;

+
+ +

P s T

+ + + + + +
+ + +

Reset one or more features of the title +modes to the default value. Normally, "reset" +disables the feature. It is possible to disable the ability +to reset features by compiling a different default for the +title modes into xterm.

+ +

P s = 0 +→ Do not set window/icon labels using hexadecimal. +
+P s
= 1 → Do not query window/icon +labels using hexadecimal.
+P s
= 2 → Do not set window/icon +labels using UTF-8.
+P s
= 3 → Do not query window/icon +labels using UTF-8. (See discussion of "Title +Modes").

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

CSI P +s X

+ + +

Erase P s +Character(s) (default = 1) (ECH).

+ + +

CSI P +s Z

+ + +

Cursor Backward Tabulation P +s tab stops (default = 1) (CBT).

+ + +

CSI P +m `

+ + +

Character Position Absolute [column] +(default = [row,1]) (HPA).

+ + +

CSI P +m a

+ + +

Character Position Relative [columns] +(default = [row,col+1]) (HPR).

+ + +

CSI P +s b

+ + +

Repeat the preceding graphic character P +s times (REP).

+ + +

CSI P +s c

+ + +

Send Device Attributes (Primary DA).

+ +

P s = 0 +or omitted → request attributes from terminal. The +response depends on the decTerminalID resource +setting.
+→ CSI ? 1 ; 2 c +(‘‘VT100 with Advanced Video +Option’’)
+→ CSI ? 1 ; 0 c +(‘‘VT101 with No Options’’)
+→ CSI ? 6 c +(‘‘VT102’’)
+→ CSI ? 6 0 ; 1 ; 2 ; 6 ; +8 ; 9 ; 1 5 ; c (‘‘VT220’’)
+The VT100-style response parameters do not mean anything by +themselves. VT220 parameters do, telling the host what +features the terminal supports:
+P s
= 1 → 132-columns.
+P s
= 2 → Printer.
+P s
= 6 → Selective erase.
+P s
= 8 → User-defined keys.
+P s
= 9 → National replacement +character sets.
+P s
= 1 5 → Technical characters. +
+P s
= 2 2 → ANSI color, e.g., VT525. +
+P s
= 2 9 → ANSI text locator (i.e., +DEC Locator mode).

+ + + + + + +
+ + +

CSI > P +s c

+ + +

Send Device Attributes (Secondary DA).

+
+ +

P s = 0 +or omitted → request the terminal’s +identification code. The response depends on the +decTerminalID resource setting. It should apply only +to VT220 and up, but xterm extends this to VT100. +
+→ CSI > P +p ; P v ; P +c c
+where P p denotes the terminal type +
+P p
= 0 → +‘‘VT100’’.
+P p
= 1 → +‘‘VT220’’.
+and P v is the firmware version (for +xterm, this was originally the XFree86 patch number, +starting with 95). In a DEC terminal, P +c indicates the ROM cartridge +registration number and is always zero.

+ + + + + + + + + + + +
+ + +

CSI P +m d

+ + +

Line Position Absolute [row] (default = +[1,column]) (VPA).

+ + +

CSI P +m e

+ + +

Line Position Relative [rows] (default = +[row+1,column]) (VPR).

+ + +

CSI P +s ; P

+
+ +

s f

+ + + + + + + + + + +
+ + +

Horizontal and Vertical Position +[row;column] (default = [1,1]) (HVP).

+ + +

CSI P +s g

+ + +

Tab Clear (TBC).

+ +

P s = 0 +→ Clear Current Column (default).
+P s
= 3 → Clear All.

+ + + + + + + +
+ + +

CSI P +m h

+ + +

Set Mode (SM).

+
+ +

P s = 2 +→ Keyboard Action Mode (AM).
+P s
= 4 → Insert Mode (IRM).
+P s
= 1 2 → Send/receive (SRM). +
+P s
= 2 0 → Automatic Newline +(LNM).

+ + + + + + +
+ + +

CSI ? P +m h

+ + +

DEC Private Mode Set (DECSET).

+
+ +

P s = 1 +→ Application Cursor Keys (DECCKM).
+P s
= 2 → Designate USASCII for +character sets G0-G3 (DECANM), and set VT100 mode.
+P s
= 3 → 132 Column Mode (DECCOLM). +
+P s
= 4 → Smooth (Slow) Scroll +(DECSCLM).
+P s
= 5 → Reverse Video (DECSCNM). +
+P s
= 6 → Origin Mode (DECOM). +
+P s
= 7 → Wraparound Mode (DECAWM). +
+P s
= 8 → Auto-repeat Keys (DECARM). +
+P s
= 9 → Send Mouse X & Y on +button press. See the section Mouse Tracking.
+P s
= 1 0 → Show toolbar (rxvt). +
+P s
= 1 2 → Start Blinking Cursor +(att610).
+P s
= 1 8 → Print form feed +(DECPFF).
+P s
= 1 9 → Set print extent to full +screen (DECPEX).
+P s
= 2 5 → Show Cursor (DECTCEM). +
+P s
= 3 0 → Show scrollbar (rxvt). +
+P s
= 3 5 → Enable font-shifting +functions (rxvt).
+P s
= 3 8 → Enter Tektronix Mode +(DECTEK).
+P s
= 4 0 → Allow 80 → 132 +Mode.
+P s
= 4 1 → more(1) fix (see +curses resource).
+P s
= 4 2 → Enable Nation +Replacement Character sets (DECNRCM).
+P s
= 4 4 → Turn On Margin Bell. +
+P s
= 4 5 → Reverse-wraparound Mode. +
+P s
= 4 6 → Start Logging. This is +normally disabled by a compile-time option.
+P s
= 4 7 → Use Alternate Screen +Buffer. (This may be disabled by the titeInhibit +resource).
+P s
= 6 6 → Application keypad +(DECNKM).
+P s
= 6 7 → Backarrow key sends +backspace (DECBKM).
+P s
= 6 9 → Enable left and right +margin mode (DECLRMM), VT420 and up.
+P s
= 9 5 → Do not clear screen when +DECCOLM is set/reset (DECNCSM), VT510 and up.
+P s
= 1 0 0 0 → Send Mouse X & Y +on button press and release. See the section Mouse +Tracking.
+P s
= 1 0 0 1 → Use Hilite Mouse +Tracking.
+P s
= 1 0 0 2 → Use Cell Motion +Mouse Tracking.
+P s
= 1 0 0 3 → Use All Motion Mouse +Tracking.
+P s
= 1 0 0 4 → Send +FocusIn/FocusOut events.
+P s
= 1 0 0 5 → Enable UTF-8 Mouse +Mode.
+P s
= 1 0 0 6 → Enable SGR Mouse +Mode.
+P s
= 1 0 1 0 → Scroll to bottom on +tty output (rxvt).
+P s
= 1 0 1 5 → Enable urxvt Mouse +Mode.
+P s
= 1 0 1 1 → Scroll to bottom on +key press (rxvt).
+P s
= 1 0 3 4 → Interpret +"meta" key, sets eighth bit. (enables the +eightBitInput resource).
+P s
= 1 0 3 5 → Enable special +modifiers for Alt and NumLock keys. (This enables the +numLock resource).
+P s
= 1 0 3 6 → Send +ESC when Meta modifies a key. +(This enables the metaSendsEscape resource).
+P s
= 1 0 3 7 → Send DEL from the +editing-keypad Delete key.
+P s
= 1 0 3 9 → Send +ESC when Alt modifies a key. +(This enables the altSendsEscape resource).
+P s
= 1 0 4 0 → Keep selection even +if not highlighted. (This enables the keepSelection +resource).
+P s
= 1 0 4 1 → Use the CLIPBOARD +selection. (This enables the selectToClipboard +resource).
+P s
= 1 0 4 2 → Enable Urgency +window manager hint when Control-G is received. (This +enables the bellIsUrgent resource).
+P s
= 1 0 4 3 → Enable raising of +the window when Control-G is received. (enables the +popOnBell resource).
+P s
= 1 0 4 7 → Use Alternate Screen +Buffer. (This may be disabled by the titeInhibit +resource).
+P s
= 1 0 4 8 → Save cursor as in +DECSC. (This may be disabled by the titeInhibit +resource).
+P s
= 1 0 4 9 → Save cursor as in +DECSC and use Alternate Screen Buffer, clearing it first. +(This may be disabled by the titeInhibit resource). +This combines the effects of the 1 0 4 7 and 1 0 4 8 modes. +Use this with terminfo-based applications rather than the 4 +7 mode.
+P s
= 1 0 5 0 → Set terminfo/termcap +function-key mode.
+P s
= 1 0 5 1 → Set Sun function-key +mode.
+P s
= 1 0 5 2 → Set HP function-key +mode.
+P s
= 1 0 5 3 → Set SCO function-key +mode.
+P s
= 1 0 6 0 → Set legacy keyboard +emulation (X11R6).
+P s
= 1 0 6 1 → Set VT220 keyboard +emulation.
+P s
= 2 0 0 4 → Set bracketed paste +mode.

+ + + + + + + +
+ + +

CSI P +m i

+ + +

Media Copy (MC).

+
+ +

P s = 0 +→ Print screen (default).
+P s
= 4 → Turn off printer +controller mode.
+P s
= 5 → Turn on printer controller +mode.

+ + + + + + +
+ + +

CSI ? P +m i

+ + +

Media Copy (MC, DEC-specific).

+
+ +

P s = 1 +→ Print line containing cursor.
+P s
= 4 → Turn off autoprint mode. +
+P s
= 5 → Turn on autoprint mode. +
+P s
= 1 0 → Print composed display, +ignores DECPEX.
+P s
= 1 1 → Print all pages.

+ + + + + + + +
+ + +

CSI P +m l

+ + +

Reset Mode (RM).

+
+ +

P s = 2 +→ Keyboard Action Mode (AM).
+P s
= 4 → Replace Mode (IRM). +
+P s
= 1 2 → Send/receive (SRM). +
+P s
= 2 0 → Normal Linefeed +(LNM).

+ + + + + + +
+ + +

CSI ? P +m l

+ + +

DEC Private Mode Reset (DECRST).

+
+ +

P s = 1 +→ Normal Cursor Keys (DECCKM).
+P s
= 2 → Designate VT52 mode +(DECANM).
+P s
= 3 → 80 Column Mode (DECCOLM). +
+P s
= 4 → Jump (Fast) Scroll +(DECSCLM).
+P s
= 5 → Normal Video (DECSCNM). +
+P s
= 6 → Normal Cursor Mode +(DECOM).
+P s
= 7 → No Wraparound Mode +(DECAWM).
+P s
= 8 → No Auto-repeat Keys +(DECARM).
+P s
= 9 → Don’t send Mouse X +& Y on button press.
+P s
= 1 0 → Hide toolbar (rxvt). +
+P s
= 1 2 → Stop Blinking Cursor +(att610).
+P s
= 1 8 → Don’t print form +feed (DECPFF).
+P s
= 1 9 → Limit print to scrolling +region (DECPEX).
+P s
= 2 5 → Hide Cursor (DECTCEM). +
+P s
= 3 0 → Don’t show +scrollbar (rxvt).
+P s
= 3 5 → Disable font-shifting +functions (rxvt).
+P s
= 4 0 → Disallow 80 → 132 +Mode.
+P s
= 4 1 → No more(1) fix +(see curses resource).
+P s
= 4 2 → Disable Nation +Replacement Character sets (DECNRCM).
+P s
= 4 4 → Turn Off Margin Bell. +
+P s
= 4 5 → No Reverse-wraparound +Mode.
+P s
= 4 6 → Stop Logging. (This is +normally disabled by a compile-time option).
+P s
= 4 7 → Use Normal Screen +Buffer.
+P s
= 6 6 → Numeric keypad (DECNKM). +
+P s
= 6 7 → Backarrow key sends +delete (DECBKM).
+P s
= 6 9 → Disable left and right +margin mode (DECLRMM), VT420 and up.
+P s
= 9 5 → Clear screen when +DECCOLM is set/reset (DECNCSM), VT510 and up.
+P s
= 1 0 0 0 → Don’t send +Mouse X & Y on button press and release. See the section +Mouse Tracking.
+P s
= 1 0 0 1 → Don’t use +Hilite Mouse Tracking.
+P s
= 1 0 0 2 → Don’t use Cell +Motion Mouse Tracking.
+P s
= 1 0 0 3 → Don’t use All +Motion Mouse Tracking.
+P s
= 1 0 0 4 → Don’t send +FocusIn/FocusOut events.
+P s
= 1 0 0 5 → Disable UTF-8 Mouse +Mode.
+P s
= 1 0 0 6 → Disable SGR Mouse +Mode.
+P s
= 1 0 1 0 → Don’t scroll +to bottom on tty output (rxvt).
+P s
= 1 0 1 5 → Disable urxvt Mouse +Mode.
+P s
= 1 0 1 1 → Don’t scroll +to bottom on key press (rxvt).
+P s
= 1 0 3 4 → Don’t +interpret "meta" key. (This disables the +eightBitInput resource).
+P s
= 1 0 3 5 → Disable special +modifiers for Alt and NumLock keys. (This disables the +numLock resource).
+P s
= 1 0 3 6 → Don’t send +ESC when Meta modifies a key. +(This disables the metaSendsEscape resource).
+P s
= 1 0 3 7 → Send VT220 Remove +from the editing-keypad Delete key.
+P s
= 1 0 3 9 → Don’t send +ESC when Alt modifies a key. +(This disables the altSendsEscape resource).
+P s
= 1 0 4 0 → Do not keep +selection when not highlighted. (This disables the +keepSelection resource).
+P s
= 1 0 4 1 → Use the PRIMARY +selection. (This disables the selectToClipboard +resource).
+P s
= 1 0 4 2 → Disable Urgency +window manager hint when Control-G is received. (This +disables the bellIsUrgent resource).
+P s
= 1 0 4 3 → Disable raising of +the window when Control-G is received. (This disables the +popOnBell resource).
+P s
= 1 0 4 7 → Use Normal Screen +Buffer, clearing screen first if in the Alternate Screen. +(This may be disabled by the titeInhibit resource). +
+P s
= 1 0 4 8 → Restore cursor as in +DECRC. (This may be disabled by the titeInhibit +resource).
+P s
= 1 0 4 9 → Use Normal Screen +Buffer and restore cursor as in DECRC. (This may be disabled +by the titeInhibit resource). This combines the +effects of the 1 0 4 7 and 1 0 4 8 modes. Use this with +terminfo-based applications rather than the 4 7 mode. +
+P s
= 1 0 5 0 → Reset +terminfo/termcap function-key mode.
+P s
= 1 0 5 1 → Reset Sun +function-key mode.
+P s
= 1 0 5 2 → Reset HP +function-key mode.
+P s
= 1 0 5 3 → Reset SCO +function-key mode.
+P s
= 1 0 6 0 → Reset legacy +keyboard emulation (X11R6).
+P s
= 1 0 6 1 → Reset keyboard +emulation to Sun/PC style.
+P s
= 2 0 0 4 → Reset bracketed +paste mode.

+ + + + + + + +
+ + +

CSI P +m m

+ + +

Character Attributes (SGR).

+
+ +

P s = 0 +→ Normal (default).
+P s
= 1 → Bold.
+P s
= 4 → Underlined.
+P s
= 5 → Blink (appears as Bold). +
+P s
= 7 → Inverse.
+P s
= 8 → Invisible, i.e., hidden +(VT300).
+P s
= 2 2 → Normal (neither bold nor +faint).
+P s
= 2 4 → Not underlined.
+P s
= 2 5 → Steady (not blinking). +
+P s
= 2 7 → Positive (not inverse). +
+P s
= 2 8 → Visible, i.e., not +hidden (VT300).
+P s
= 3 0 → Set foreground color to +Black.
+P s
= 3 1 → Set foreground color to +Red.
+P s
= 3 2 → Set foreground color to +Green.
+P s
= 3 3 → Set foreground color to +Yellow.
+P s
= 3 4 → Set foreground color to +Blue.
+P s
= 3 5 → Set foreground color to +Magenta.
+P s
= 3 6 → Set foreground color to +Cyan.
+P s
= 3 7 → Set foreground color to +White.
+P s
= 3 9 → Set foreground color to +default (original).
+P s
= 4 0 → Set background color to +Black.
+P s
= 4 1 → Set background color to +Red.
+P s
= 4 2 → Set background color to +Green.
+P s
= 4 3 → Set background color to +Yellow.
+P s
= 4 4 → Set background color to +Blue.
+P s
= 4 5 → Set background color to +Magenta.
+P s
= 4 6 → Set background color to +Cyan.
+P s
= 4 7 → Set background color to +White.
+P s
= 4 9 → Set background color to +default (original).

+ +

If 16-color +support is compiled, the following apply. Assume that +xterm’s resources are set so that the ISO color +codes are the first 8 of a set of 16. Then the +aixterm colors are the bright versions of the ISO +colors:
+P s
= 9 0 → Set foreground color to +Black.
+P s
= 9 1 → Set foreground color to +Red.
+P s
= 9 2 → Set foreground color to +Green.
+P s
= 9 3 → Set foreground color to +Yellow.
+P s
= 9 4 → Set foreground color to +Blue.
+P s
= 9 5 → Set foreground color to +Magenta.
+P s
= 9 6 → Set foreground color to +Cyan.
+P s
= 9 7 → Set foreground color to +White.
+P s
= 1 0 0 → Set background color +to Black.
+P s
= 1 0 1 → Set background color +to Red.
+P s
= 1 0 2 → Set background color +to Green.
+P s
= 1 0 3 → Set background color +to Yellow.
+P s
= 1 0 4 → Set background color +to Blue.
+P s
= 1 0 5 → Set background color +to Magenta.
+P s
= 1 0 6 → Set background color +to Cyan.
+P s
= 1 0 7 → Set background color +to White.

+ +

If xterm +is compiled with the 16-color support disabled, it supports +the following, from rxvt:
+P s
= 1 0 0 → Set foreground and +background color to default.

+ +

If 88- or +256-color support is compiled, the following apply.
+P s
= 3 8 ; 5 ; P s +→ Set foreground color to the second P +s .
+P s
= 4 8 ; 5 ; P s +→ Set background color to the second P +s .

+ + + + + +
+ + + +

CSI +> P s ; P s +m

+
+ +

Set or reset resource-values +used by xterm to decide whether to construct escape +sequences holding information about the modifiers pressed +with a given key. The first parameter identifies the +resource to set/reset. The second parameter is the value to +assign to the resource. If the second parameter is omitted, +the resource is reset to its initial value.
+P s
= 1 → modifyCursorKeys.
+P s
= 2 → modifyFunctionKeys. +
+P s
= 4 → modifyOtherKeys.
+If no parameters are given, all resources are reset to their +initial values.

+ + + + + + + +
+ + +

CSI P +s n

+ + +

Device Status Report (DSR).

+
+ +

P s = 5 +→ Status Report. Result +(‘‘OK’’) is
+CSI
0 n
+P s
= 6 → Report Cursor Position +(CPR) [row;column]. Result is
+CSI
r ; c R

+ + + + + +
+ + +

CSI > P +s n

+ + +

Disable modifiers which may be enabled via +the CSI > P +s ; P s m sequence. +This corresponds to a resource value of "-1", +which cannot be set with the other sequence. The parameter +identifies the resource to be disabled:

+ +

P s = 1 +→ modifyCursorKeys.
+P s
= 2 → modifyFunctionKeys. +
+P s
= 4 → modifyOtherKeys.
+If the parameter is omitted, modifyFunctionKeys is +disabled. When modifyFunctionKeys is disabled, +xterm uses the modifier keys to make an extended +sequence of functions rather than adding a parameter to each +function key to denote the modifiers.

+ + + + + + +
+ + +

CSI ? P +s n

+ + +

Device Status Report (DSR, +DEC-specific).

+
+ +

P s = 6 +→ Report Cursor Position (DECXCPR) [row;column] as +CSI ? r ; c R +(assumes the default page, i.e., "1").
+P s
= 1 5 → Report Printer status as +CSI ? 1 0 n (ready). or +CSI ? 1 1 n (not ready). +
+P s
= 2 5 → Report UDK status as +CSI ? 2 0 n (unlocked) or +CSI ? 2 1 n (locked).
+P s
= 2 6 → Report Keyboard status +as
+CSI
? 2 7 ; 1 ; 0 ; 0 n (North American). +
+The last two parameters apply to VT400 & up, and denote +keyboard ready and LK01 respectively.
+P s
= 5 3 → Report Locator status as +CSI ? 5 3 n Locator available, +if compiled-in, or CSI ? 5 0 n +No Locator, if not.
+P s
= 6 2 → Report macro space +(DECMSR) as CSI P +n \* {
+P s
= 6 3 → Report memory checksum +(DECCKSR) as DCS P +t ! x x x x +ST
+P t
is the request id (from an optional +parameter to the request).
+The x’s are hexadecimal digits 0-9 and A-F.
+P s
= 7 5 → Report data integrity as +CSI ? 7 0 n (ready, no errors) +
+P s
= 8 5 → Report multi-session +configuration as CSI ? 8 3 n +(not configured for multiple-session operation).

+ + + + + +
+ + +

CSI > P +s p

+ + +

Set resource value pointerMode. This +is used by xterm to decide whether to hide the +pointer cursor as the user types. Valid values for the +parameter:

+ +

P s = 0 +→ never hide the pointer.
+P s
= 1 → hide if the mouse tracking +mode is not enabled.
+P s
= 2 → always hide the pointer. +If no parameter is given, xterm uses the default, +which is 1 .

+ + + + + + + + +
+ + +

CSI ! p

+ + +

Soft terminal reset (DECSTR).

+ + +

CSI P +s $ p

+ + +

Request ANSI mode (DECRQM). For VT300 and +up, reply is

+ + +

CSI +P s ; P m $ y +
+where P s is the mode number as in RM, +and P m is the mode value:
+0 - not recognized
+1 - set
+2 - reset
+3 - permanently set
+4 - permanently reset

+ + + + + +
+ + +

CSI ? P +s $ p

+
+ +

Request DEC private mode +(DECRQM). For VT300 and up, reply is
+CSI
? P s ; P +m $ p
+where P s is the mode number as in +DECSET, P m is the mode value as in +the ANSI DECRQM.

+ + + + + +
+ + +

CSI P +s ; P s “ +p

+
+ +

Set conformance level (DECSCL). +Valid values for the first parameter:
+P s
= 6 1 → VT100.
+P s
= 6 2 → VT200.
+P s
= 6 3 → VT300.
+Valid values for the second parameter:
+P s
= 0 → 8-bit controls.
+P s
= 1 → 7-bit controls (always set +for VT100).
+P s
= 2 → 8-bit controls.

+ + + + + + + +
+ + +

CSI P +s q

+ + +

Load LEDs (DECLL).

+
+ +

P s = 0 +→ Clear all LEDS (default).
+P s
= 1 → Light Num Lock.
+P s
= 2 → Light Caps Lock.
+P s
= 3 → Light Scroll Lock.
+P s
= 2 1 → Extinguish Num Lock. +
+P s
= 2 2 → Extinguish Caps Lock. +
+P s
= 2 3 → Extinguish Scroll +Lock.

+ + + + + +
+ + +

CSI P +s SP q

+
+ +

Set cursor style (DECSCUSR, +VT520).
+P s
= 0 → blinking block.
+P s
= 1 → blinking block (default). +
+P s
= 2 → steady block.
+P s
= 3 → blinking underline. +
+P s
= 4 → steady underline.

+ + + + + +
+ + +

CSI P +s “ q

+ + +

Select character protection attribute +(DECSCA). Valid values for the parameter:

+ +

P s = 0 +→ DECSED and DECSEL can erase (default).
+P s
= 1 → DECSED and DECSEL cannot +erase.
+P s
= 2 → DECSED and DECSEL can +erase.

+ + + + + +
+ + +

CSI P +s ; P s r

+
+ +

Set Scrolling Region +[top;bottom] (default = full size of window) (DECSTBM).

+ + + + + + + + +
+ + +

CSI ? P +m r

+ + +

Restore DEC Private Mode Values. The value +of P s previously saved is restored. +P s values are the same as for +DECSET.

+ + +

CSI P +t ; P l

+
+ +

; P b ; P +r ; P s $ r

+ + + + + +
+ + +

Change Attributes in Rectangular Area +(DECCARA), VT400 and up.

+ +

P t ; +P l ; P b ; P +r denotes the rectangle.
+P s
denotes the SGR attributes to change: +0, 1, 4, 5, 7.

+ + + + + +
+ + +

CSI P +l ; P r s

+
+ +

Set left and right margins +(DECSLRM), available only when DECLRMM is enabled (VT420 and +up).

+ + + + + + + + + + + +
+ + +

CSI s

+ + +

Save cursor (ANSI.SYS), available only when +DECLRMM is disabled.

+ + +

CSI ? P +m s

+ + +

Save DEC Private Mode Values. P +s values are the same as for DECSET.

+ + +

CSI P +s ; P

+
+ +

s ; P +s t

+ + + + + +
+ + +

Window manipulation (from dtterm, as +well as extensions). These controls may be disabled using +the allowWindowOps resource. Valid values for the +first (and any additional parameters) are:

+ +

P s = 1 +→ De-iconify window.
+P s
= 2 → Iconify window.
+P s
= 3 ; x ; y → Move window +to [x, y].
+P s
= 4 ; height ; width → +Resize the xterm window to given height and width in +pixels. Omitted parameters reuse the current height or +width. Zero parameters use the display’s height or +width.
+P s
= 5 → Raise the xterm +window to the front of the stacking order.
+P s
= 6 → Lower the xterm +window to the bottom of the stacking order.
+P s
= 7 → Refresh the xterm +window.
+P s
= 8 ; height ; width → +Resize the text area to given height and width in +characters. Omitted parameters reuse the current height or +width. Zero parameters use the display’s height or +width.
+P s
= 9 ; 0 → Restore maximized +window.
+P s
= 9 ; 1 → Maximize window (i.e., +resize to screen size).
+P s
= 1 0 ; 0 → Undo full-screen +mode.
+P s
= 1 0 ; 1 → Change to +full-screen.
+P s
= 1 1 → Report xterm +window state. If the xterm window is open +(non-iconified), it returns +CSI 1 t . If the xterm +window is iconified, it returns +CSI 2 t .
+P s
= 1 3 → Report xterm +window position. Result is CSI +3 ; x ; y t
+P s
= 1 4 → Report xterm +window in pixels. Result is +CSI 4 ; height ; +width t
+P s
= 1 8 → Report the size of the +text area in characters. Result is +CSI 8 ; height ; +width t
+P s
= 1 9 → Report the size of the +screen in characters. Result is +CSI 9 ; height ; +width t
+P s
= 2 0 → Report xterm +window’s icon label. Result is +OSC L label +ST
+P s
= 2 1 → Report xterm +window’s title. Result is +OSC l label +ST
+P s
= 2 2 ; 0 → Save xterm +icon and window title on stack.
+P s
= 2 2 ; 1 → Save xterm +icon title on stack.
+P s
= 2 2 ; 2 → Save xterm +window title on stack.
+P s
= 2 3 ; 0 → Restore xterm +icon and window title from stack.
+P s
= 2 3 ; 1 → Restore xterm +icon title from stack.
+P s
= 2 3 ; 2 → Restore xterm +window title from stack.
+P s
>= 2 4 → Resize to P +s lines (DECSLPP).

+ + + + + +
+ + +

CSI P +t ; P l ; P +b ; P r ; P +s $ t

+
+ +

Reverse Attributes in +Rectangular Area (DECRARA), VT400 and up.
+P t
; P l ; P +b ; P r denotes the +rectangle.
+P s
denotes the attributes to reverse, +i.e., 1, 4, 5, 7.

+ + + + + +
+ + +

CSI > P +s ; P s t

+
+ +

Set one or more features of the +title modes. Each parameter enables a single feature. +
+P s
= 0 → Set window/icon labels +using hexadecimal.
+P s
= 1 → Query window/icon labels +using hexadecimal.
+P s
= 2 → Set window/icon labels +using UTF-8.
+P s
= 3 → Query window/icon labels +using UTF-8. (See discussion of "Title Modes")

+ + + + + +
+ + +

CSI P +s SP t

+
+ +

Set warning-bell volume +(DECSWBV, VT520).
+P s
= 0 or 1 → off.
+P s
= 2 , 3 or 4 → low.
+P s
= 5 , 6 , 7 , or 8 → high.

+ + + + + + + + + + + + +
+ + +

CSI u

+ + +

Restore cursor (ANSI.SYS).

+
+ + +

CSI P +s SP

+
+ +

u

+ + + + + + +
+ + +

Set margin-bell volume (DECSMBV, +VT520).

+
+ +

P s = 1 +→ off.
+P s
= 2 , 3 or 4 → low.
+P s
= 0 , 5 , 6 , 7 , or 8 → +high.

+ + + + + +
+ + +

CSI P +t ; P l ; P +b ; P r ; P +p ; P t ; P +l ; P p $ v

+
+ +

Copy Rectangular Area (DECCRA, +VT400 and up).
+P t
; P l ; P +b ; P r denotes the +rectangle.
+P p
denotes the source page.
+P t
; P l denotes +the target location.
+P p
denotes the target page.

+ + + + + +
+ + +

CSI P +t ; P l ; P +b ; P r ’ +w

+
+ +

Enable Filter Rectangle +(DECEFR), VT420 and up.
+Parameters are [top;left;bottom;right].
+Defines the coordinates of a filter rectangle and activates +it. Anytime the locator is detected outside of the filter +rectangle, an outside rectangle event is generated and the +rectangle is disabled. Filter rectangles are always treated +as "one-shot" events. Any parameters that are +omitted default to the current locator position. If all +parameters are omitted, any locator motion will be reported. +DECELR always cancels any prevous rectangle definition.

+ + + + + + + +
+ + +

CSI P +s x

+ + +

Request Terminal Parameters +(DECREQTPARM).

+
+ +

if P s is +a "0" (default) or "1", and xterm +is emulating VT100, the control sequence elicits a response +of the same form whose parameters describe the terminal: +
+P s
→ the given P +s incremented by 2.
+P n
= 1 ← no parity.
+P n
= 1 ← eight bits.
+P n
= 1 ← 2 8 transmit 38.4k baud. +
+P n
= 1 ← 2 8 receive 38.4k baud. +
+P n
= 1 ← clock multiplier.
+P n
= 0 ← STP flags.

+ + + + + + +
+ + +

CSI P +s * x

+ + +

Select Attribute Change Extent +(DECSACE).

+
+ +

P s = 0 +→ from start to end position, wrapped.
+P s
= 1 → from start to end +position, wrapped.
+P s
= 2 → rectangle (exact).

+ + + + + +
+ + +

CSI P +i ; P g ; P +t ; P l ; P +b ; P r * y

+
+ +

Request Checksum of Rectangular +Area (DECRQCRA), VT420 and up. Response is +
+DCS
P t ! x x x x +ST
+P i
is the request id.
+P g
is the page number.
+P t
; P l ; P +b ; P r denotes the +rectangle.
+The x’s are hexadecimal digits 0-9 and A-F.

+ + + + + +
+ + +

CSI P +c ; P t ; P +l ; P b ; P +r $ x

+
+ +

Fill Rectangular Area (DECFRA), +VT420 and up.
+P c
is the character to use.
+P t
; P l ; P +b ; P r denotes the +rectangle.

+ + + + + +
+ + +

CSI P +s ; P u ’ +z

+
+ +

Enable Locator Reporting +(DECELR).
+Valid values for the first parameter:
+P s
= 0 → Locator disabled +(default).
+P s
= 1 → Locator enabled.
+P s
= 2 → Locator enabled for one +report, then disabled.
+The second parameter specifies the coordinate unit for +locator reports.
+Valid values for the second parameter:
+P u
= 0 ← or omitted → default +to character cells.
+P u
= 1 ← device physical pixels. +
+P u
= 2 ← character cells.

+ + + + + +
+ + +

CSI P +t ; P l ; P +b ; P r $ z

+
+ +

Erase Rectangular Area +(DECERA), VT400 and up.
+P t
; P l ; P +b ; P r denotes the +rectangle.

+ + + + + + +
+ + +

CSI P +m ’ {

+ + +

Select Locator Events (DECSLE).

+
+ +

Valid values for the first (and +any additional parameters) are:
+P s
= 0 → only respond to explicit +host requests (DECRQLP).
+(This is default). It also cancels any filter
+rectangle.
+P s
= 1 → report button down +transitions.
+P s
= 2 → do not report button down +transitions.
+P s
= 3 → report button up +transitions.
+P s
= 4 → do not report button up +transitions.

+ + + + + +
+ + +

CSI P +t ; P l ; P +b ; P r $ {

+
+ +

Selective Erase Rectangular +Area (DECSERA), VT400 and up.
+P t
; P l ; P +b ; P r denotes the +rectangle.

+ + + + + + +
+ + +

CSI P +s ’ |

+ + +

Request Locator Position (DECRQLP).

+
+ +

Valid values for the parameter +are:
+P s
= 0 , 1 or omitted → transmit a +single DECLRP locator report.

+ +

If Locator +Reporting has been enabled by a DECELR, xterm will respond +with a DECLRP Locator Report. This report is also generated +on button up and down events if they have been enabled with +a DECSLE, or when the locator is detected outside of a +filter rectangle, if filter rectangles have been enabled +with a DECEFR.

+ +

→ +CSI P e +; P b ; P r ; +P c ; P p & +w

+ +

Parameters are +[event;button;row;column;page].
+Valid values for the event:
+P e
= 0 → locator unavailable - no +other parameters sent.
+P e
= 1 → request - xterm received a +DECRQLP.
+P e
= 2 → left button down.
+P e
= 3 → left button up.
+P e
= 4 → middle button down. +
+P e
= 5 → middle button up.
+P e
= 6 → right button down.
+P e
= 7 → right button up.
+P e
= 8 → M4 button down.
+P e
= 9 → M4 button up.
+P e
= 1 0 → locator outside filter +rectangle.
+‘‘button’’ parameter is a bitmask +indicating which buttons are pressed:
+P b
= 0 ← no buttons down.
+P b
& 1 ← right button down. +
+P b
& 2 ← middle button down. +
+P b
& 4 ← left button down. +
+P b
& 8 ← M4 button down.
+‘‘row’’ and +‘‘column’’ parameters are the +coordinates of the locator position in the xterm window, +encoded as ASCII decimal.
+The ‘‘page’’ parameter is not used +by xterm, and will be omitted.

+ + + + + +
+ + +

CSI P +m SP }

+
+ +

Insert P +s Column(s) (default = 1) (DECIC), VT420 +and up.

+ + + + + +
+ + +

CSI P +m SP ~

+
+ +

Delete P +s Column(s) (default = 1) (DECDC), VT420 +and up.

+ +

Operating System +Controls

+ + + + + + + + +
+ + +

OSC P +s ; P t +ST

+
+ + +

OSC P +s ; P t +BEL

+
+ +

Set Text Parameters. For colors +and font, if P t is a "?", +the control sequence elicits a response which consists of +the control sequence which would set the corresponding +value. The dtterm control sequences allow you to +determine the icon name and window title.
+P s
= 0 → Change Icon Name and +Window Title to P t .
+P s
= 1 → Change Icon Name to P +t .
+P s
= 2 → Change Window Title to +P t .
+P s
= 3 → Set X property on +top-level window. P t should be in the +form "prop=value", or just +"prop" to delete the property
+P s
= 4 ; c ; spec → Change +Color Number c to the color specified by spec. +This can be a name or RGB specification as per +XParseColor. Any number of c name pairs may be +given. The color numbers correspond to the ANSI colors 0-7, +their bright versions 8-15, and if supported, the remainder +of the 88-color or 256-color table.

+ +

If a +"?" is given rather than a name or RGB +specification, xterm replies with a control sequence of the +same form which can be used to set the corresponding color. +Because more than one pair of color number and specification +can be given in one control sequence, xterm can make +more than one reply.

+ +

P +s = 5 ; c ; spec → Change +Special Color Number c to the color specified by +spec. This can be a name or RGB specification as per +XParseColor. Any number of c name pairs may be +given. The special colors can also be set by adding the +maximum number of colors to these codes in an +OSC 4 control:

+ +

P +c = 0 ← resource colorBD +(BOLD).
+P c
= 1 ← resource colorUL +(UNDERLINE).
+P c
= 2 ← resource colorBL +(BLINK).
+P c
= 3 ← resource colorRV +(REVERSE).

+ +

The 10 colors +(below) which may be set or queried using 1 0 through 1 9 +are denoted dynamic colors, since the corresponding +control sequences were the first means for setting +xterm’s colors dynamically, i.e., after it was +started. They are not the same as the ANSI colors. These +controls may be disabled using the allowColorOps +resource. At least one parameter is expected for P +t . Each successive parameter changes the +next color in the list. The value of P +s tells the starting point in the list. +The colors are specified by name or RGB specification as per +XParseColor.

+ +

If a +"?" is given rather than a name or RGB +specification, xterm replies with a control sequence of the +same form which can be used to set the corresponding dynamic +color. Because more than one pair of color number and +specification can be given in one control sequence, +xterm can make more than one reply.

+ +

P +s = 1 0 → Change VT100 text +foreground color to P t .
+P s
= 1 1 → Change VT100 text +background color to P t .
+P s
= 1 2 → Change text cursor color +to P t .
+P s
= 1 3 → Change mouse foreground +color to P t .
+P s
= 1 4 → Change mouse background +color to P t .
+P s
= 1 5 → Change Tektronix +foreground color to P t .
+P s
= 1 6 → Change Tektronix +background color to P t .
+P s
= 1 7 → Change highlight +background color to P t .
+P s
= 1 8 → Change Tektronix cursor +color to P t .
+P s
= 1 9 → Change highlight +foreground color to P t .

+ +

P +s = 4 6 → Change Log File to P +t . (This is normally disabled by a +compile-time option).

+ +

P +s = 5 0 → Set Font to P +t . These controls may be disabled using +the allowFontOps resource. If P +t begins with a "#", index in +the font menu, relative (if the next character is a plus or +minus sign) or absolute. A number is expected but not +required after the sign (the default is the current entry +for relative, zero for absolute indexing).
+The same rule (plus or minus sign, optional number) is used +when querying the font. The remainder of P +t is ignored.
+A font can be specified after a "#" index +expression, by adding a space and then the font specifier. +
+If the "TrueType Fonts" menu entry is set (the +renderFont resource), then this control sets/queries +the faceName resource.

+ +

P +s = 5 1 (reserved for Emacs shell).

+ +

P +s = 5 2 → Manipulate Selection Data. +These controls may be disabled using the +allowWindowOps resource. The parameter P +t is parsed as

+ + + + + +
+ + +

P c ; P +d

+ +

The first, P +c , may contain zero or more characters +from the set c p s 0 1 2 3 4 5 6 7 . It is used to construct +a list of selection parameters for clipboard, primary, +select, or cut buffers 0 through 7 respectively, in the +order given. If the parameter is empty, xterm uses s +0 , to specify the configurable primary/clipboard selection +and cut buffer 0.
+The second parameter, P d , gives the +selection data. Normally this is a string encoded in base64. +The data becomes the new selection, which is then available +for pasting by other applications.
+If the second parameter is a ? , xterm replies to the +host with the selection data encoded using the same +protocol.
+If the second parameter is neither a base64 string nor ? , +then the selection is cleared.

+ +

P +s = 1 0 4 ; c → Reset Color +Number c. It is reset to the color specified by the +corresponding X resource. Any number of c parameters +may be given. These parameters correspond to the ANSI colors +0-7, their bright versions 8-15, and if supported, the +remainder of the 88-color or 256-color table. If no +parameters are given, the entire table will be reset.

+ +

P +s = 1 0 5 ; c → Reset Special +Color Number c. It is reset to the color specified by +the corresponding X resource. Any number of c +parameters may be given. These parameters correspond to the +special colors which can be set using an +OSC 5 control (or by adding +the maximum number of colors using an +OSC 4 control).

+ +

The dynamic +colors can also be reset to their default (resource) +values:
+P s
= 1 1 0 → Reset VT100 text +foreground color.
+P s
= 1 1 1 → Reset VT100 text +background color.
+P s
= 1 1 2 → Reset text cursor +color.
+P s
= 1 1 3 → Reset mouse foreground +color.
+P s
= 1 1 4 → Reset mouse background +color.
+P s
= 1 1 5 → Reset Tektronix +foreground color.
+P s
= 1 1 6 → Reset Tektronix +background color.
+P s
= 1 1 7 → Reset highlight color. +
+P s
= 1 1 8 → Reset Tektronix cursor +color.

+ +

Privacy +Message

+ + + + + + +
+ + +

PM P +t ST

+ + +

xterm implements no +PM functions; P +t is ignored. P t +need not be printable characters.

+ + +

Alt and Meta Keys

+ + +

Many keyboards have +keys labeled "Alt". Few have keys labeled +"Meta". However, xterm’s default +translations use the Meta modifier. Common keyboard +configurations assign the Meta modifier to an +"Alt" key. By using xmodmap one may have +the modifier assigned to a different key, and have +"real" alt and meta keys. Here is an example:

+ +

! put meta on +mod3 to distinguish it from alt
+keycode 64 = Alt_L
+clear mod1
+add mod1 = Alt_L
+keycode 115 = Meta_L
+clear mod3
+add mod3 = Meta_L

+ +

The +metaSendsEscape resource (and altSendsEscape +if altIsNotMeta is set) can be used to control the +way the Meta modifier applies to ordinary keys unless +the modifyOtherKeys resource is set:

+ +

- prefix a key with the +ESC character.
+- shift the key from codes 0-127 to 128-255 by adding +128.

+ +

The table shows the +result for a given character "x" with modifiers +according to the default translations with the resources set +on or off. This assumes altIsNotMeta is set:

+ + +

Image grohtml-285551.png

+ + +

PC-Style Function Keys

+ + +

If xterm +does minimal translation of the function keys, it usually +does this with a PC-style keyboard, so PC-style function +keys result. Sun keyboards are similar to PC keyboards. Both +have cursor and scrolling operations printed on the keypad, +which duplicate the smaller cursor and scrolling +keypads.

+ +

X does not +predefine NumLock (used for VT220 keyboards) or Alt (used as +an extension for the Sun/PC keyboards) as modifiers. These +keys are recognized as modifiers when enabled by the +numLock resource, or by the "DECSET 1 0 3 5 +" control sequence.

+ +

The cursor keys +transmit the following escape sequences depending on the +mode specified via the DECCKM escape sequence.

+ + +

Image grohtml-285552.png

+ +

The home- and end-keys (unlike PageUp and +other keys also on the 6-key editing keypad) are considered +"cursor keys" by xterm. Their mode is also +controlled by the DECCKM escape sequence:

+ + +

Image grohtml-285553.png

+ +

The application +keypad transmits the following escape sequences depending on +the mode specified via the DECPNM and DECPAM +escape sequences. Use the NumLock key to override the +application mode.

+ +

Not all keys are +present on the Sun/PC keypad (e.g., PF1, Tab), but are +supported by the program.

+ + +

Image grohtml-285554.png

+ +

They also provide 12 function keys, as well +as a few other special-purpose keys:

+ + +

Image grohtml-285555.png

+ +

Older versions of +xterm implement different escape sequences for F1 +through F4. These can be activated by setting the +oldXtermFKeys resource. However, since they do not +correspond to any hardware terminal, they have been +deprecated. (The DEC VT220 reserves F1 through F5 for local +functions such as Setup).

+ + +

Image grohtml-285556.png

+ +

In normal mode, i.e., a Sun/PC keyboard +when the sunKeyboard resource is false, xterm +recognizes function key modifiers which are parameters +appended before the final character of the control +sequence.

+ + +

Image grohtml-285557.png

+ +

For example, shift-F5 would be sent as +CSI 1 5 ; 2 ~

+ +

If the +alwaysUseMods resource is set, the Meta modifier also +is recognized, making parameters 9 through 16.

+ + +

VT220-Style Function Keys

+ + +

However, +xterm is most useful as a DEC VT102 or VT220 +emulator. Set the sunKeyboard resource to true to +force a Sun/PC keyboard to act like a VT220 keyboard.

+ +

The VT102/VT220 +application keypad transmits unique escape sequences in +application mode, which are distinct from the cursor and +scrolling keypad:

+ + +

Image grohtml-285558.png

+ +

The VT220 provides a 6-key editing keypad, +which is analogous to that on the PC keyboard. It is not +affected by DECCKM or +DECPNM/DECPAM:

+ + +

Image grohtml-285559.png

+ +

The VT220 provides 8 additional function +keys. With a Sun/PC keyboard, access these keys by +Control/F1 for F13, etc.

+ + +

Image grohtml-2855510.png

+ + +

VT52-Style Function Keys

+ + +

A VT52 does not +have function keys, but it does have a numeric keypad and +cursor keys. They differ from the other emulations by the +prefix. Also, the cursor keys do not change:

+ + +

Image grohtml-2855511.png

+ +

The keypad is similar:

+ + +

Image grohtml-2855512.png

+ + +

Sun-Style Function Keys

+ + +

The xterm +program provides support for Sun keyboards more directly, by +a menu toggle that causes it to send Sun-style function key +codes rather than VT220. Note, however, that the sun +and VT100 emulations are not really compatible. For +example, their wrap-margin behavior differs.

+ +

Only function keys +are altered; keypad and cursor keys are the same. The +emulation responds identically. See the xterm-sun terminfo +entry for details.

+ + +

HP-Style Function Keys

+ + +

Similarly, +xterm can be compiled to support HP keyboards. See +the xterm-hp terminfo entry for details.

+ + +

The Alternate Screen Buffer

+ + +

Xterm +maintains two screen buffers. The normal screen buffer +allows you to scroll back to view saved lines of output up +to the maximum set by the saveLines resource. The +alternate screen buffer is exactly as large as the display, +contains no additional saved lines. When the alternate +screen buffer is active, you cannot scroll back to view +saved lines. Xterm provides control sequences and +menu entries for switching between the two.

+ +

Most full-screen +applications use terminfo or termcap to obtain strings used +to start/stop full-screen mode, i.e., smcup and +rmcup for terminfo, or the corresponding ti +and te for termcap. The titeInhibit resource +removes the ti and te strings from the TERMCAP +string which is set in the environment for some platforms. +That is not done when xterm is built with terminfo +libraries because terminfo does not provide the whole text +of the termcap data in one piece. It would not work for +terminfo anyway, since terminfo data is not passed in +environment variables; setting an environment variable in +this manner would have no effect on the application’s +ability to switch between normal and alternate screen +buffers. Instead, the newer private mode controls (such as 1 +0 4 9 ) for switching between normal and alternate screen +buffers simply disable the switching. They add other +features such as clearing the display for the same reason: +to make the details of switching independent of the +application that requests the switch.

+ + +

Bracketed Paste Mode

+ + +

When bracketed +paste mode is set, pasted text is bracketed with control +sequences so that the program can differentiate pasted text +from typed-in text. When bracketed paste mode is set, the +program will receive:
+ESC
[ 200 ~,
+followed by the pasted text, followed by
+ESC
[ 201 ~.

+ + +

Title Modes

+ + +

The window- and +icon-labels can be set or queried using control sequences. +As a VT220-emulator, xterm "should" limit +the character encoding for the corresponding strings to +ISO-8859-1. Indeed, it used to be the case (and was +documented) that window titles had to be ISO-8859-1. This is +no longer the case. However, there are many applications +which still assume that titles are set using ISO-8859-1. So +that is the default behavior.

+ +

If xterm is +running with UTF-8 encoding, it is possible to use window- +and icon-labels encoded using UTF-8. That is because the +underlying X libraries (and many, but not all) window +managers support this feature.

+ +

The +utf8Title X resource setting tells xterm to +disable a reconversion of the title string back to +ISO-8859-1, allowing the title strings to be interpreted as +UTF-8. The same feature can be enabled using the title mode +control sequence described in this summary.

+ +

Separate from the +ability to set the titles, xterm provides the ability +to query the titles, returning them either in ISO-8859-1 or +UTF-8. This choice is available only while xterm is +using UTF-8 encoding.

+ +

Finally, the +characters sent to, or returned by a title control are less +constrained than the rest of the control sequences. To make +them more manageable (and constrained), for use in shell +scripts, xterm has an optional feature which decodes +the string from hexadecimal (for setting titles) or for +encoding the title into hexadecimal when querying the +value.

+ + +

Mouse Tracking

+ + +

The VT widget can +be set to send the mouse position and other information on +button presses. These modes are typically used by editors +and other full-screen applications that want to make use of +the mouse.

+ +

There are two sets +of mutually exclusive modes:

+ + + + + + + + + + + + +
+ + +

+ + +

mouse protocol

+
+ + +

+ + +

protocol encoding

+
+ +

The mouse protocols +include DEC Locator mode, enabled by the DECELR +CSI P s +; P s ’ z control sequence, and +is not described here (control sequences are summarized +above). The remaining five modes of the mouse protocols are +each enabled (or disabled) by a different parameter in the +"DECSET CSI ? P +m h " or "DECRST +CSI ? P +m l " control sequence.

+ +

Manifest constants +for the parameter values are defined in xcharmouse.h +as follows:

+ +

#define +SET_X10_MOUSE 9
+#define SET_VT200_MOUSE 1000
+#define SET_VT200_HIGHLIGHT_MOUSE 1001
+#define SET_BTN_EVENT_MOUSE 1002
+#define SET_ANY_EVENT_MOUSE 1003

+ +

#define +SET_FOCUS_EVENT_MOUSE 1004

+ +

#define +SET_EXT_MODE_MOUSE 1005
+#define SET_SGR_EXT_MODE_MOUSE 1006
+#define SET_URXVT_EXT_MODE_MOUSE 1015

+ +

The motion +reporting modes are strictly xterm extensions, and +are not part of any standard, though they are analogous to +the DEC VT200 DECELR locator reports.

+ +

Normally, +parameters (such as pointer position and button number) for +all mouse tracking escape sequences generated by +xterm encode numeric parameters in a single character +as value+32. For example, ! specifies the value 1. +The upper left character position on the terminal is denoted +as 1,1. This scheme dates back to X10, though the normal +mouse-tracking (from X11) is more elaborate.

+ +

X10 compatibility +mode sends an escape sequence only on button press, encoding +the location and the mouse button pressed. It is enabled by +specifying parameter 9 to DECSET. On button press, +xterm sends CSI M C +b C x C y +(6 characters).

+ + + + + + + + + + +
+ + +

+ + +

C b is +button−1.

+ + +

+ + +

C x and C +y are the x and y coordinates of the +mouse when the button was pressed.

+ +

Normal tracking +mode sends an escape sequence on both button press and +release. Modifier key (shift, ctrl, meta) information is +also sent. It is enabled by specifying parameter 1000 to +DECSET. On button press or release, xterm sends +CSI M C b C +x C y .

+ + + + + + + + + + + + + + +
+ + +

+ + +

The low two bits of C +b encode button information: 0=MB1 +pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release.

+ + +

+ + +

The next three bits encode the modifiers +which were down when the button was pressed and are added +together: 4=Shift, 8=Meta, 16=Control. Note however that the +shift and control bits are normally unavailable because +xterm uses the control modifier with mouse for popup +menus, and the shift modifier is used in the default +translations for button events. The Meta modifier +recognized by xterm is the mod1 mask, and is +not necessarily the "Meta" key (see +xmodmap).

+ + +

+ + +

C x and C +y are the x and y coordinates of the +mouse event, encoded as in X10 mode.

+ +

Wheel mice may +return buttons 4 and 5. Those buttons are represented by the +same event codes as buttons 1 and 2 respectively, except +that 64 is added to the event code. Release events for the +wheel buttons are not reported.

+ +

Mouse highlight +tracking notifies a program of a button press, receives a +range of lines from the program, highlights the region +covered by the mouse within that range until button release, +and then sends the program the release coordinates. It is +enabled by specifying parameter 1001 to DECSET. Highlighting +is performed only for button 1, though other button events +can be received.

+ +

Warning: use +of this mode requires a cooperating program or it will hang +xterm.

+ +

On button press, +the same information as for normal tracking is generated; +xterm then waits for the program to send mouse +tracking information. All X events are ignored until the +proper escape sequence is received from the pty: +CSI P s +; P s ; P s ; +P s ; P s T . +The parameters are func, startx, starty, firstrow, +and lastrow. func is non-zero to initiate highlight +tracking and zero to abort. startx and starty +give the starting x and y location for the highlighted +region. The ending location tracks the mouse, but will never +be above row firstrow and will always be above row +lastrow. (The top of the screen is row 1.) When the +button is released, xterm reports the ending position +one of two ways:

+ + + + + + + +
+ + +

+ + +

if the start and end coordinates are the +same locations:

+
+ + +

CSI +t C x C y .

+ + + + + + + +
+ + +

+ + +

otherwise:

+
+ + +

CSI +T C x C y C +x C y C x C +y .
+The parameters are startx, starty, endx, endy, +mousex, and mousey.

+ + + + + + + + + + + + +
+ + +

+ + +

startx, starty, endx, and +endy give the starting and ending character positions +of the region.

+ + +

+ + +

mousex and mousey give the +location of the mouse at button up, which may not be over a +character.

+ +

Button-event +tracking is essentially the same as normal tracking, but +xterm also reports button-motion events. Motion +events are reported only if the mouse pointer has moved to a +different character cell. It is enabled by specifying +parameter 1002 to DECSET. On button press or release, +xterm sends the same codes used by normal tracking +mode.

+ + + + + + + + + + +
+ + +

+ + +

On button-motion events, xterm adds +32 to the event code (the third character, C +b ).

+ + +

+ + +

The other bits of the event code specify +button and modifier keys as in normal mode. For example, +motion into cell x,y with button 1 down is reported as +CSI M @ C x +C y . ( @ = 32 + 0 (button 1) + 32 +(motion indicator) ). Similarly, motion with button 3 +down is reported as CSI M B +C x C y . ( B = 32 ++ 2 (button 3) + 32 (motion indicator) ).

+ +

Any-event mode is +the same as button-event mode, except that all motion events +are reported, even if no mouse button is down. It is enabled +by specifying 1003 to DECSET.

+ +

FocusIn/FocusOut +can be combined with any of the mouse events since it uses a +different protocol. When set, it causes xterm to send +CSI I when the terminal gains +focus, and CSI O when it loses +focus.

+ +

The original X10 +mouse protocol limits the C x and C +y ordinates to 223 (=255 - 32). +Xterm supports more than one scheme for extending +this range, by changing the protocol encoding:

+ + + + + +
+ + +

UTF-8 (1005)

+
+ +

This enables UTF-8 encoding for +C x and C y +under all tracking modes, expanding the maximum encodable +position from 223 to 2015. For positions less than 95, the +resulting output is identical under both modes. Under +extended mouse mode, positions greater than 95 generate +"extra" bytes which will confuse applications +which do not treat their input as a UTF-8 stream. Likewise, +C b will be UTF-8 encoded, to reduce +confusion with wheel mouse events.
+Under normal mouse mode, positions outside (160,94) result +in byte pairs which can be interpreted as a single UTF-8 +character; applications which do treat their input as UTF-8 +will almost certainly be confused unless extended mouse mode +is active.
+This scheme has the drawback that the encoded coordinates +will not pass through luit unchanged, e.g., for +locales using non-UTF-8 encoding.

+ + + + + +
+ + +

SGR (1006)

+ + +

The normal mouse response is altered to use +CSI < followed by +semicolon-separated encoded button value, the C +x and C y ordinates +and a final character which is M for button press and m for +button release.

+ +

The encoded button value in +this case does not add 32 since that was useful only in the +X10 scheme for ensuring that the byte containing the button +value is a printable code. The modifiers are encoded in the +same way. A different final character is used for button +release to resolve the X10 ambiguity regarding which button +was released.
+The highlight tracking responses are also modified to an +SGR-like format, using the same SGR-style scheme and +button-encodings.

+ + + + + +
+ + +

URXVT (1015)

+
+ +

The normal mouse response is +altered to use CSI followed by +semicolon-separated encoded button value, the C +x and C y ordinates +and final character M .
+This uses the same button encoding as X10, but printing it +as a decimal integer rather than as a single byte.
+However, CSI M can be mistaken +for DL (delete lines), while the highlight tracking +CSI T can be mistaken for SD +(scroll down), and the Window manipulation controls. For +these reasons, the 1015 control is not recommended; it is +not an improvement over 1005.

+ + +

Tektronix 4014 Mode

+ + +

Most of these +sequences are standard Tektronix 4014 control sequences. +Graph mode supports the 12-bit addressing of the Tektronix +4014. The major features missing are the write-through and +defocused modes. This document does not describe the +commands used in the various Tektronix plotting modes but +does describe the commands to switch modes.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +

BEL

+ + +

Bell (Ctrl-G).

+ + +

BS

+ + +

Backspace (Ctrl-H).

+ + +

TAB

+ + +

Horizontal Tab (Ctrl-I).

+ + +

LF

+ + +

Line Feed or New Line (Ctrl-J).

+ + +

VT

+ + +

Cursor up (Ctrl-K).

+ + +

FF

+ + +

Form Feed or New Page (Ctrl-L).

+ + +

CR

+ + +

Carriage Return (Ctrl-M).

+ + +

ESC ETX

+ + +

Switch to VT100 Mode ( +ESC Ctrl-C).

+ + +

ESC ENQ

+ + +

Return Terminal Status ( +ESC Ctrl-E).

+ + +

ESC FF

+ + +

PAGE (Clear Screen) ( +ESC Ctrl-L).

+ + +

ESC SO

+ + +

Begin 4015 APL mode ( +ESC Ctrl-N). (This is ignored +by xterm).

+ + +

ESC SI

+ + +

End 4015 APL mode ( +ESC Ctrl-O). (This is ignored +by xterm).

+ + +

ESC ETB

+ + +

COPY (Save Tektronix Codes to file +COPYyyyy-mm-dd.hh:mm:ss).

+ + +

ETB +(end transmission block) is the same as Ctrl-W.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

ESC CAN

+ + +

Bypass Condition ( +ESC Ctrl-X).

+
+ + +

ESC SUB

+ + +

GIN mode ( +ESC Ctrl-Z).

+
+ + +

ESC FS

+ + +

Special Point Plot Mode ( +ESC Ctrl-\).

+
+ + +

ESC 8

+ + +

Select Large Character Set.

+
+ + +

ESC 9

+ + +

Select #2 Character Set.

+
+ + +

ESC :

+ + +

Select #3 Character Set.

+
+ + +

ESC ;

+ + +

Select Small Character Set.

+
+ + +

OSC P +s ; P

+
+ +

t +BEL

+ + + + + + +
+ + +

Set Text Parameters of VT window.

+
+ +

P s = 0 +→ Change Icon Name and Window Title to P +t .
+P s
= 1 → Change Icon Name to P +t .
+P s
= 2 → Change Window Title to +P t .
+P s
= 4 6 → Change Log File to P +t . (This is normally disabled by a +compile-time option).

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +

ESC `

+ + +

Normal Z Axis and Normal (solid) +Vectors.

+
+ + +

ESC a

+ + +

Normal Z Axis and Dotted Line Vectors.

+
+ + +

ESC b

+ + +

Normal Z Axis and Dot-Dashed Vectors.

+
+ + +

ESC c

+ + +

Normal Z Axis and Short-Dashed Vectors.

+
+ + +

ESC d

+ + +

Normal Z Axis and Long-Dashed Vectors.

+
+ + +

ESC h

+ + +

Defocused Z Axis and Normal (solid) +Vectors.

+
+ + +

ESC i

+ + +

Defocused Z Axis and Dotted Line +Vectors.

+
+ + +

ESC j

+ + +

Defocused Z Axis and Dot-Dashed +Vectors.

+
+ + +

ESC k

+ + +

Defocused Z Axis and Short-Dashed +Vectors.

+
+ + +

ESC l

+ + +

Defocused Z Axis and Long-Dashed +Vectors.

+
+ + +

ESC p

+ + +

Write-Thru Mode and Normal (solid) +Vectors.

+
+ + +

ESC q

+ + +

Write-Thru Mode and Dotted Line +Vectors.

+
+ + +

ESC r

+ + +

Write-Thru Mode and Dot-Dashed Vectors.

+
+ + +

ESC s

+ + +

Write-Thru Mode and Short-Dashed +Vectors.

+
+ + +

ESC t

+ + +

Write-Thru Mode and Long-Dashed +Vectors.

+
+ + +

FS

+ + +

Point Plot Mode (Ctrl-\).

+
+ + +

GS

+ + +

Graph Mode (Ctrl-]).

+
+ + +

RS

+ + +

Incremental Plot Mode (Ctrl-^).

+
+ + +

US

+ + +

Alpha Mode (Ctrl-_).

+
+ + +

VT52 Mode

+ + +

Parameters for +cursor movement are at the end of the +ESC Y escape sequence. Each +ordinate is encoded in a single character as +value+32. For example, ! is 1. The screen coordinate +system is 0-based.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +

ESC +A

+ + +

Cursor up.

+
+ + +

ESC B

+ + +

Cursor down.

+
+ + +

ESC C

+ + +

Cursor right.

+
+ + +

ESC D

+ + +

Cursor left.

+
+ + +

ESC F

+ + +

Enter graphics mode.

+
+ + +

ESC G

+ + +

Exit graphics mode.

+
+ + +

ESC H

+ + +

Move the cursor to the home position.

+
+ + +

ESC I

+ + +

Reverse line feed.

+
+ + +

ESC J

+ + +

Erase from the cursor to the end of the +screen.

+
+ + +

ESC K

+ + +

Erase from the cursor to the end of the +line.

+
+ + +

ESC Y P +s P

+
+ +

s

+ + + + + + + + + + + + +
+ + +

Move the cursor to given row and +column.

+
+ + +

ESC Z

+ + +

Identify.

+
+ +

→ +ESC / Z (‘‘I am a +VT52.’’).

+ + + + + + + + + + + + + + + + + +
+ + +

ESC =

+ + +

Enter alternate keypad mode.

+
+ + +

ESC >

+ + +

Exit alternate keypad mode.

+
+ + +

ESC <

+ + +

Exit VT52 mode (Enter VT100 mode).

+
+
+ + diff --git a/yat/tests/auto/auto.pro b/yat/tests/auto/auto.pro new file mode 100644 index 0000000..99efd58 --- /dev/null +++ b/yat/tests/auto/auto.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = \ + block diff --git a/yat/tests/auto/block/block.pro b/yat/tests/auto/block/block.pro new file mode 100644 index 0000000..ea88f5e --- /dev/null +++ b/yat/tests/auto/block/block.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +QT += testlib quick + +include(../../../backend/backend.pri) + +SOURCES += \ + tst_block.cpp \ + diff --git a/yat/tests/auto/block/tst_block.cpp b/yat/tests/auto/block/tst_block.cpp new file mode 100644 index 0000000..a4f197e --- /dev/null +++ b/yat/tests/auto/block/tst_block.cpp @@ -0,0 +1,950 @@ +#include "../../../backend/block.h" +#include + +#include +#include "../../../backend/screen.h" +#include "../../../backend/screen_data.h" + +class BlockHandler +{ +public: + BlockHandler(bool fill) { + screen.setHeight(5); + int width = 100; + screen.setWidth(width); + (*screen.currentScreenData()->it_for_row(0))->clear(); + if (fill) { + QString spaces(width, QChar(' ')); + block()->replaceAtPos(0, spaces, screen.defaultTextStyle()); + } + QCOMPARE(block()->style_list().size(), 1); + default_style = block()->style_list().at(0); + default_text_style = default_style.style; + } + + Block *block() const + { + return *screen.currentScreenData()->it_for_row(0); + } + + void doneChanges() + { + screen.dispatchChanges(); + } + + TextStyle default_style; + TextStyle::Styles default_text_style; + Screen screen; +}; + +class tst_Block: public QObject +{ + Q_OBJECT + +private slots: + void replaceStart(); + void replaceEdgeOfStyle(); + void replaceCompatibleStyle(); + void replaceCompatiblePreviousStyle(); + void replaceCompatiblePreviousStyleShouldRemove(); + void replaceCompatibleCurrentStyleShouldRemove(); + void replaceIncompatibleStyle(); + void replaceIncompaitibleStylesCrossesBoundary(); + void replace3IncompatibleStyles(); + void replaceIncomaptibleStylesCrosses2Boundaries(); + void replaceIncompatibleColor(); + void replaceRemoveOverlappedStyles(); + void replaceSwapStyles(); + void replaceEndBlock(); + void clearBlock(); + void clearToEndOfBlock1Segment(); + void clearToEndOfBlock3Segment(); + void clearToEndOfBlockMiddle3Segment(); + void deleteCharacters1Segment(); + void deleteCharacters2Segments(); + void deleteCharacters3Segments(); + void deleteCharactersRemoveSegmentEnd(); + void deleteCharactersRemoveSegmentBeginning(); + void deleteCharactersRemoveMiddle(); + void insertCharacters(); + void insertCharacters2Segments(); + void insertCharacters3Segments(); +}; + +void tst_Block::replaceStart() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QVector old_style_list = block->style_list(); + QCOMPARE(old_style_list.size(), 1); + + QString replace_text("This is a test"); + TextStyle textStyle; + textStyle.style = TextStyle::Overlined; + block->replaceAtPos(0,replace_text, textStyle); + + QVector new_style_list = block->style_list(); + TextStyleLine first_style = new_style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, replace_text.size() - 1); + QCOMPARE(new_style_list.size(), 2); + +} + +void tst_Block::replaceEdgeOfStyle() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString first_text("This is the First"); + TextStyle textStyle; + textStyle.style = TextStyle::Overlined; + block->replaceAtPos(0,first_text, textStyle); + + QString second_text("This is the Second"); + textStyle.style = TextStyle::Bold; + block->replaceAtPos(first_text.size(), second_text, textStyle); + + QVector style_list = block->style_list(); + + QCOMPARE(style_list.size(), 3); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.style, TextStyle::Overlined); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, first_text.size() - 1); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.style, TextStyle::Bold); + QCOMPARE(second_style.start_index, first_text.size()); + QCOMPARE(second_style.end_index, first_text.size()+ second_text.size() - 1); + + const TextStyleLine &third_style = style_list.at(2); + QCOMPARE(third_style.style, TextStyle::Normal); + QCOMPARE(third_style.start_index, first_text.size()+ second_text.size()); +} + +void tst_Block::replaceCompatibleStyle() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString replace_text("replaceed Text"); + block->replaceAtPos(10, replace_text, blockHandler.default_style); + + QVector after_style_list = block->style_list(); + QCOMPARE(after_style_list.size(), 1); + QCOMPARE(after_style_list.at(0).style, blockHandler.default_text_style); +} + +void tst_Block::replaceCompatiblePreviousStyle() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + TextStyle first_style = blockHandler.default_style; + first_style.style = TextStyle::Blinking; + QString first_text("first"); + block->replaceAtPos(0,first_text, first_style); + + TextStyle second_style = blockHandler.default_style; + second_style.style = TextStyle::Bold; + QString second_text("this is the second text"); + block->replaceAtPos(first_text.size(), second_text, second_style); + + QString third_text("third"); + block->replaceAtPos(first_text.size(), third_text,first_style); + + blockHandler.doneChanges(); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 3); + + const TextStyleLine &first_check_style = style_list.at(0); + QCOMPARE(first_check_style.start_index, 0); + QCOMPARE(first_check_style.end_index, (first_text.size() -1) + third_text.size()); + + const TextStyleLine &second_check_style = style_list.at(1); + QCOMPARE(second_check_style.start_index, first_text.size() + third_text.size()); + QCOMPARE(second_check_style.end_index, (first_text.size() -1) + second_text.size()); + + const TextStyleLine &third_check_style = style_list.at(2); + QCOMPARE(third_check_style.start_index, first_text.size() + second_text.size()); +} + +void tst_Block::replaceCompatiblePreviousStyleShouldRemove() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + TextStyle first_style = blockHandler.default_style; + first_style.style = TextStyle::Blinking; + QString first_text("first"); + block->replaceAtPos(0,first_text, first_style); + + TextStyle second_style = blockHandler.default_style; + second_style.style = TextStyle::Bold; + QString second_text("second"); + block->replaceAtPos(first_text.size(), second_text, second_style); + + QString third_text("this is the third"); + block->replaceAtPos(first_text.size(), third_text,first_style); + + blockHandler.doneChanges(); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 2); + + const TextStyleLine &first_check_style = style_list.at(0); + QCOMPARE(first_check_style.start_index, 0); + QCOMPARE(first_check_style.end_index, (first_text.size() -1) + third_text.size()); + + const TextStyleLine &second_check_style = style_list.at(1); + QCOMPARE(second_check_style.start_index, first_text.size() + third_text.size()); + +} + +void tst_Block::replaceCompatibleCurrentStyleShouldRemove() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + TextStyle first_style = blockHandler.default_style; + first_style.style = TextStyle::Blinking; + QString first_text("first"); + block->replaceAtPos(0,first_text, first_style); + + TextStyle second_style = blockHandler.default_style; + second_style.style = TextStyle::Bold; + QString second_text("second"); + block->replaceAtPos(first_text.size(), second_text, second_style); + + QString third_text("second"); + block->replaceAtPos(first_text.size(), third_text,first_style); + + blockHandler.doneChanges(); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 2); + + const TextStyleLine &first_check_style = style_list.at(0); + QCOMPARE(first_check_style.start_index, 0); + QCOMPARE(first_check_style.end_index, (first_text.size() -1) + third_text.size()); + + const TextStyleLine &second_check_style = style_list.at(1); + QCOMPARE(second_check_style.start_index, first_text.size() + third_text.size()); + +} + +void tst_Block::replaceIncompatibleStyle() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + + QString replace_text("replaceed Text"); + TextStyle replace_style; + replace_style.style = TextStyle::Blinking; + block->replaceAtPos(10, replace_text, replace_style); + + QVector after_style_list = block->style_list(); + QCOMPARE(after_style_list.size(), 3); + + const TextStyleLine &first_style = after_style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, 9); + QCOMPARE(first_style.style, blockHandler.default_text_style); + + const TextStyleLine &second_style = after_style_list.at(1); + QCOMPARE(second_style.start_index, 10); + QCOMPARE(second_style.end_index, 10 + replace_text.size() -1); + QCOMPARE(second_style.style, TextStyle::Blinking); + + const TextStyleLine &third_style = after_style_list.at(2); + QCOMPARE(third_style.start_index, 10 + replace_text.size()); + QCOMPARE(third_style.style, blockHandler.default_text_style); +} + +void tst_Block::replaceIncompaitibleStylesCrossesBoundary() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString replace_text("replaceed Text"); + TextStyle replace_style; + replace_style.style = TextStyle::Blinking; + block->replaceAtPos(0, replace_text, replace_style); + + QString crosses_boundary("New incompatible text"); + replace_style.style = TextStyle::Framed; + int replace_pos = replace_text.size()/2; + block->replaceAtPos(replace_pos, crosses_boundary, replace_style); + + QVector after_style_list = block->style_list(); + QCOMPARE(after_style_list.size(), 3); + + const TextStyleLine &first_style = after_style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, replace_pos -1); + QCOMPARE(first_style.style, TextStyle::Blinking); + + const TextStyleLine &second_style = after_style_list.at(1); + QCOMPARE(second_style.start_index, replace_pos); + QCOMPARE(second_style.end_index, replace_pos + crosses_boundary.size() -1); + QCOMPARE(second_style.style, TextStyle::Framed); + + const TextStyleLine &third_style = after_style_list.at(2); + QCOMPARE(third_style.start_index, replace_pos + crosses_boundary.size()); + QCOMPARE(third_style.style, blockHandler.default_text_style); +} + +void tst_Block::replace3IncompatibleStyles() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString first_text("First Text"); + TextStyle replace_style; + replace_style.style = TextStyle::Blinking; + block->replaceAtPos(0, first_text, replace_style); + + QString second_text("Second Text"); + replace_style.style = TextStyle::Italic; + block->replaceAtPos(first_text.size(), second_text, replace_style); + + QString third_text("Third Text"); + replace_style.style = TextStyle::Encircled; + block->replaceAtPos(first_text.size() + second_text.size(), third_text, replace_style); + + QCOMPARE(block->style_list().size(), 4); + + QVector after_style_list = block->style_list(); + + const TextStyleLine &first_style = after_style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, first_text.size() -1); + + const TextStyleLine &second_style = after_style_list.at(1); + QCOMPARE(second_style.start_index, first_text.size()); + QCOMPARE(second_style.end_index, first_text.size() + second_text.size() - 1); + QCOMPARE(second_style.style, TextStyle::Italic); + + const TextStyleLine &third_style = after_style_list.at(2); + QCOMPARE(third_style.start_index, first_text.size() + second_text.size()); + QCOMPARE(third_style.end_index, first_text.size() + second_text.size() + third_text.size() - 1); + QCOMPARE(third_style.style, TextStyle::Encircled); + + const TextStyleLine &fourth_style = after_style_list.at(3); + QCOMPARE(fourth_style.start_index, first_text.size() + second_text.size() + third_text.size()); +} +void tst_Block::replaceIncomaptibleStylesCrosses2Boundaries() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString first_text("First Text"); + TextStyle replace_style; + replace_style.style = TextStyle::Blinking; + block->replaceAtPos(0, first_text, replace_style); + + QString second_text("Second Text"); + replace_style.style = TextStyle::Italic; + block->replaceAtPos(first_text.size(), second_text, replace_style); + + QString third_text("Third Text"); + replace_style.style = TextStyle::Encircled; + block->replaceAtPos(first_text.size() + second_text.size(), third_text, replace_style); + + QCOMPARE(block->style_list().size(), 4); + + QVector before_style_list = block->style_list(); + + QString overlap_first_third; + overlap_first_third.fill(QChar('A'), second_text.size() + 4); + replace_style.style = TextStyle::DoubleUnderlined; + block->replaceAtPos(first_text.size() -2, overlap_first_third, replace_style); + + QVector after_style_list = block->style_list(); + QCOMPARE(block->style_list().size(), 4); + + const TextStyleLine &first_style = after_style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, first_text.size() - 3); + QCOMPARE(first_style.style, TextStyle::Blinking); + + const TextStyleLine &second_style = after_style_list.at(1); + QCOMPARE(second_style.style, TextStyle::DoubleUnderlined); + QCOMPARE(second_style.start_index, first_text.size() - 2); + QCOMPARE(second_style.end_index, first_text.size() - 2 + overlap_first_third.size() -1); + + const TextStyleLine &third_style = after_style_list.at(2); + QCOMPARE(third_style.style, TextStyle::Encircled); + QCOMPARE(third_style.start_index, first_text.size() - 2 + overlap_first_third.size()); + QCOMPARE(third_style.end_index, first_text.size() - 2 + overlap_first_third.size() + third_text.size() - 1 - 2); + + const TextStyleLine &fourth_style = after_style_list.at(3); + QCOMPARE(fourth_style.style, blockHandler.default_text_style); + QCOMPARE(fourth_style.start_index, first_text.size() - 2 + overlap_first_third.size() + third_text.size() - 2); +} + +void tst_Block::replaceIncompatibleColor() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString first_text("291 "); + TextStyleLine replace_style; + replace_style.forground = ColorPalette::Yellow; + block->replaceAtPos(0,first_text, replace_style); + + QString second_text("QPointF Screen::selectionAreaStart() "); + replace_style.forground = blockHandler.default_style.forground; + block->replaceAtPos(first_text.size(), second_text, replace_style); + + QString third_text("const"); + replace_style.forground = ColorPalette::Green; + block->replaceAtPos(first_text.size() + second_text.size(), third_text, replace_style); + + QString brackets("()"); + replace_style.forground = ColorPalette::Cyan; + block->replaceAtPos(38, brackets, replace_style); + + QVector after_style_list = block->style_list(); + + const TextStyleLine &first_style = after_style_list.at(0); + QCOMPARE(first_style.forground, ColorPalette::Yellow); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, first_text.size() - 1); + + const TextStyleLine &second_style = after_style_list.at(1); + QCOMPARE(second_style.forground, blockHandler.default_style.forground); + QCOMPARE(second_style.start_index, first_text.size()); + QCOMPARE(second_style.end_index, 37); + + const TextStyleLine &third_style = after_style_list.at(2); + QCOMPARE(third_style.forground, ColorPalette::Cyan); + QCOMPARE(third_style.start_index, 38); + QCOMPARE(third_style.end_index, 38 + brackets.size() -1); + + const TextStyleLine &fourth_style = after_style_list.at(3); + QCOMPARE(fourth_style.forground, blockHandler.default_style.forground); + QCOMPARE(fourth_style.start_index, 38 + brackets.size()); + QCOMPARE(fourth_style.end_index, first_text.size() + second_text.size() -1); + +} + +void tst_Block::replaceRemoveOverlappedStyles() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString first_text("First Text"); + TextStyle replace_style; + replace_style.style = TextStyle::Blinking; + block->replaceAtPos(0, first_text, replace_style); + + QString second_text("Second Text"); + replace_style.style = TextStyle::Italic; + block->replaceAtPos(first_text.size(), second_text, replace_style); + + QString third_text("Third Text"); + replace_style.style = TextStyle::Encircled; + block->replaceAtPos(first_text.size() + second_text.size(), third_text, replace_style); + + QString fourth_text = third_text + second_text; + fourth_text.chop(1); + replace_style.style = TextStyle::Bold; + block->replaceAtPos(first_text.size(), fourth_text, replace_style); + + QCOMPARE(block->style_list().size(), 4); +} +void tst_Block::replaceSwapStyles() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString first_text("First Text"); + TextStyle replace_style; + replace_style.style = TextStyle::Blinking; + block->replaceAtPos(0, first_text, replace_style); + + QString second_text("Second Text"); + replace_style.style = TextStyle::Italic; + block->replaceAtPos(first_text.size(), second_text, replace_style); + + QString third_text("Third Text"); + replace_style.style = TextStyle::Encircled; + block->replaceAtPos(first_text.size() + second_text.size(), third_text, replace_style); + + QString replace_second("Dnoces Text"); + replace_style.style = TextStyle::Bold; + block->replaceAtPos(first_text.size(), replace_second, replace_style); + + QCOMPARE(block->style_list().size(), 4); +} + +void tst_Block::replaceEndBlock() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString *full_block = block->textLine(); + int block_size = full_block->size(); + + QString replace_text("at the end of the string"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Bold; + block->replaceAtPos(block_size - replace_text.size(), replace_text, style); + + QCOMPARE(block->textLine()->size(), block_size); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 2); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, block_size - replace_text.size() -1); + QCOMPARE(first_style.style, blockHandler.default_text_style); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, block_size - replace_text.size()); + QCOMPARE(second_style.end_index, block_size - 1); + QCOMPARE(second_style.style, TextStyle::Bold); +} + +void tst_Block::clearBlock() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QVERIFY(block->textLine()->size() > 0); + QCOMPARE(block->textLine()->trimmed().size(), 0); +} + +void tst_Block::clearToEndOfBlock1Segment() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString replace_text("To be replaceed"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Encircled; + block->replaceAtPos(0, replace_text, style); + + int before_clear_size = block->textLine()->size(); + + block->clearCharacters(5, blockHandler.screen.width() -1); + + blockHandler.doneChanges(); + + int after_clear_size = block->textLine()->size(); + QCOMPARE(after_clear_size, before_clear_size); + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 2); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, 4); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, 5); + + QString cleared("To be"); + QCOMPARE(block->textLine()->trimmed(), cleared); +} + +void tst_Block::clearToEndOfBlock3Segment() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString replace_text("To be"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Encircled; + block->replaceAtPos(0, replace_text, style); + + QString replace_text2(" or not to be"); + style.style = TextStyle::Bold; + block ->replaceAtPos(replace_text.size(), replace_text2, style); + + block->clearCharacters(replace_text.size(), blockHandler.screen.width() - 1); + + blockHandler.doneChanges(); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 2); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, replace_text.size() - 1); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, replace_text.size()); + QCOMPARE(second_style.style, blockHandler.default_text_style); +} + +void tst_Block::clearToEndOfBlockMiddle3Segment() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString replace_text("To be"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Encircled; + block->replaceAtPos(0, replace_text, style); + + QString replace_text2(" or not to be"); + style.style = TextStyle::Bold; + block ->replaceAtPos(replace_text.size(), replace_text2, style); + + block->clearCharacters(replace_text.size() + 3, blockHandler.screen.width() - 1); + + blockHandler.doneChanges(); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 3); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, replace_text.size() - 1); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, replace_text.size()); + QCOMPARE(second_style.end_index, replace_text.size() + 2); + + const TextStyleLine &third_style = style_list.at(2); + QCOMPARE(third_style.start_index, replace_text.size() + 3); + QCOMPARE(third_style.style, blockHandler.default_text_style); +} + +void tst_Block::deleteCharacters1Segment() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString replace_text("replaceing some text"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Encircled; + block->replaceAtPos(0, replace_text, style); + + QString *full_block = block->textLine(); + int block_size = full_block->size(); + + block->deleteCharacters(10,14); + + QCOMPARE(block->textLine()->size(), block_size - 5); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 2); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, 14); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, 15); + QCOMPARE(second_style.style, blockHandler.default_text_style); +} + +void tst_Block::deleteCharacters2Segments() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString replace_text("replaceing some text"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Encircled; + block->replaceAtPos(0, replace_text, style); + + QString *full_block = block->textLine(); + int block_size = full_block->size(); + + block->deleteCharacters(15,25); + + QCOMPARE(block->textLine()->size(), block_size - 11); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 2); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, 14); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, 15); + QCOMPARE(second_style.style, blockHandler.default_text_style); + +} + +void tst_Block::deleteCharacters3Segments() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString replace_text("replaceing some text"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Encircled; + block->replaceAtPos(0, replace_text, style); + + QString replace_more_text("Some more text"); + style.style = TextStyle::Bold; + block->replaceAtPos(replace_text.size(), replace_more_text, style); + + QString *full_block = block->textLine(); + int block_size = full_block->size(); + + block->deleteCharacters(10,15); + + QCOMPARE(block->textLine()->size(), block_size - 6); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 3); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, 13); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, 14); + QCOMPARE(second_style.end_index, 14 + replace_more_text.size() -1); + QCOMPARE(second_style.style, TextStyle::Bold); + + const TextStyleLine &third_style = style_list.at(2); + QCOMPARE(third_style.start_index, 14 + replace_more_text.size()); + QCOMPARE(third_style.style, blockHandler.default_text_style); +} + +void tst_Block::deleteCharactersRemoveSegmentEnd() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString replace_text("replaceing some text"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Encircled; + block->replaceAtPos(0, replace_text, style); + + QString replace_more_text("Some more text"); + style.style = TextStyle::Bold; + block->replaceAtPos(replace_text.size(), replace_more_text, style); + + QString *full_block = block->textLine(); + int block_size = full_block->size(); + + block->deleteCharacters(16,33); + + QCOMPARE(block->textLine()->size(), block_size - ((33 - 16) + 1)); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 2); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, 15); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, 16); + QCOMPARE(second_style.style, blockHandler.default_text_style); + +} + +void tst_Block::deleteCharactersRemoveSegmentBeginning() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString replace_text("replaceing some text"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Encircled; + block->replaceAtPos(0, replace_text, style); + + QString replace_more_text("Some more text"); + style.style = TextStyle::Bold; + block->replaceAtPos(replace_text.size(), replace_more_text, style); + + QString *full_block = block->textLine(); + int block_size = full_block->size(); + + block->deleteCharacters(replace_text.size(),replace_text.size() + replace_more_text.size() + 3); + + int expected_size = block_size -1 - ((replace_text.size() + replace_more_text.size() + 3 ) - replace_text.size()); + QCOMPARE(block->textLine()->size(), expected_size); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 2); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, replace_text.size() - 1); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, replace_text.size()); + QCOMPARE(second_style.style, blockHandler.default_text_style); +} + +void tst_Block::deleteCharactersRemoveMiddle() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString insert_text('A'); + int old_width = blockHandler.screen.width(); + QString empty(old_width - 2, ' '); + insert_text += empty + 'B'; + block->replaceAtPos(0, insert_text, blockHandler.default_style); + + Q_ASSERT(old_width == blockHandler.screen.width()); + Q_ASSERT(insert_text == *block->textLine()); + + block->deleteCharacters(1, old_width - 2); + + Q_ASSERT(QString("AB") == block->textLine()->trimmed()); +} + +void tst_Block::insertCharacters() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString *full_block = block->textLine(); + int block_size = full_block->size(); + + QString insert_text("inserting some text"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Encircled; + block->insertAtPos(5, insert_text, style); + + int expected_size = block_size + insert_text.size(); + + QCOMPARE(block->textLine()->size(), expected_size); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 3); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, 4); + QCOMPARE(first_style.style, blockHandler.default_text_style); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, 5); + QCOMPARE(second_style.end_index, 5 + insert_text.size() -1); + QCOMPARE(second_style.style, TextStyle::Encircled); + + const TextStyleLine &third_style = style_list.at(2); + QCOMPARE(third_style.start_index, 5 + insert_text.size()); + QCOMPARE(third_style.end_index, expected_size - 1); + QCOMPARE(third_style.style, blockHandler.default_text_style); +} + +void tst_Block::insertCharacters2Segments() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString *full_block = block->textLine(); + int block_size = full_block->size(); + + QString replace_text("at the end of the string"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Bold; + block->replaceAtPos(block_size - replace_text.size(), replace_text, style); + + QString insert_text("inserting some text"); + style.style = TextStyle::Encircled; + block->insertAtPos(5, insert_text, style); + + int expected_size = block_size + insert_text.size(); + QCOMPARE(block->textLine()->size(), expected_size); + + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 4); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, 4); + QCOMPARE(first_style.style, blockHandler.default_text_style); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, 5); + QCOMPARE(second_style.end_index, 5 + insert_text.size() -1); + QCOMPARE(second_style.style, TextStyle::Encircled); + + const TextStyleLine &third_style = style_list.at(2); + QCOMPARE(third_style.start_index, 5 + insert_text.size()); + QCOMPARE(third_style.end_index, block_size -1 - replace_text.size() + insert_text.size()); + QCOMPARE(third_style.style, blockHandler.default_text_style); + + const TextStyleLine &fourth_style = style_list.at(3); + QCOMPARE(fourth_style.start_index, block_size - replace_text.size() + insert_text.size()); + QCOMPARE(fourth_style.end_index, expected_size - 1 ); + QCOMPARE(fourth_style.style, TextStyle::Bold); +} + +void tst_Block::insertCharacters3Segments() +{ + BlockHandler blockHandler(true); + Block *block = blockHandler.block(); + + QString *full_block = block->textLine(); + int block_size = full_block->size(); + + QString replace_text("at the end of the string"); + TextStyle style = blockHandler.default_style; + style.style = TextStyle::Bold; + block->replaceAtPos(block_size - replace_text.size(), replace_text, style); + + QString replace_text2("somewhere in the string"); + style.style = TextStyle::Encircled; + block->replaceAtPos(20,replace_text2, style); + + QVector tmp_style_list = block->style_list(); + QCOMPARE(tmp_style_list.size(), 4); + + QString insert_text("this text is longer than last segment"); + style.style = TextStyle::Italic; + block->insertAtPos(10, insert_text, style); + + blockHandler.doneChanges(); + + int expected_size = block_size + insert_text.size(); + QCOMPARE(block->textLine()->size(), expected_size); + + block->printStyleList(); + QVector style_list = block->style_list(); + QCOMPARE(style_list.size(), 6); + + const TextStyleLine &first_style = style_list.at(0); + QCOMPARE(first_style.start_index, 0); + QCOMPARE(first_style.end_index, 9); + QCOMPARE(first_style.style, blockHandler.default_text_style); + + const TextStyleLine &second_style = style_list.at(1); + QCOMPARE(second_style.start_index, 10); + QCOMPARE(second_style.end_index, 10 + insert_text.size() -1); + QCOMPARE(second_style.style, TextStyle::Italic); + + const TextStyleLine &third_style = style_list.at(2); + QCOMPARE(third_style.start_index, 10 + insert_text.size()); + QCOMPARE(third_style.end_index, 20 + insert_text.size() - 1); + QCOMPARE(third_style.style, blockHandler.default_text_style); + + const TextStyleLine &fourth_style = style_list.at(3); + QCOMPARE(fourth_style.start_index, 20 + insert_text.size()); + QCOMPARE(fourth_style.end_index, 20 + insert_text.size() + replace_text2.size() - 1); + QCOMPARE(fourth_style.style, TextStyle::Encircled); + + const TextStyleLine &fith_style = style_list.at(4); + QCOMPARE(fith_style.start_index, 20 + insert_text.size() + replace_text2.size()); + QCOMPARE(fith_style.end_index, block_size - replace_text.size() + insert_text.size() - 1); + QCOMPARE(fith_style.style, blockHandler.default_text_style); + + const TextStyleLine &sixth_style = style_list.at(5); + QCOMPARE(sixth_style.start_index, block_size - replace_text.size() + insert_text.size()); + QCOMPARE(sixth_style.end_index, block_size + insert_text.size() - 1); + QCOMPARE(sixth_style.style, TextStyle::Bold); +} + +#include +QTEST_MAIN(tst_Block); diff --git a/yat/tests/tests.pro b/yat/tests/tests.pro new file mode 100644 index 0000000..b8445a7 --- /dev/null +++ b/yat/tests/tests.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = \ + auto diff --git a/yat/yat.pro b/yat/yat.pro new file mode 100644 index 0000000..fabc7b4 --- /dev/null +++ b/yat/yat.pro @@ -0,0 +1,5 @@ +TEMPLATE=subdirs +CONFIG += ordered +SUBDIRS= \ + yat_declarative \ + tests diff --git a/yat/yat_declarative/main.cpp b/yat/yat_declarative/main.cpp new file mode 100644 index 0000000..bf18cd3 --- /dev/null +++ b/yat/yat_declarative/main.cpp @@ -0,0 +1,46 @@ +/************************************************************************************************** +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +* associated documentation files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, publish, distribute, +* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +* OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +***************************************************************************************************/ + +#include +#include +#include + +#include + +#include "register_qml_types.h" +#include "terminal_screen.h" +#include "yat_pty.h" + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + register_qml_types(); + + QQmlEngine engine; + QQmlComponent component(&engine, QUrl("qrc:/qml/yat_declarative/main.qml")); + auto errors = component.errors(); + for (int i = 0; i < errors.size(); i++) { + qDebug() << errors.at(i).toString(); + } + component.create(); + + return app.exec(); +} diff --git a/yat/yat_declarative/mono_text.cpp b/yat/yat_declarative/mono_text.cpp new file mode 100644 index 0000000..c0fb4f2 --- /dev/null +++ b/yat/yat_declarative/mono_text.cpp @@ -0,0 +1,249 @@ +/****************************************************************************** +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +******************************************************************************/ + +#include "mono_text.h" + +#include +#include +#include +#include +#include + +class MonoSGNode : public QSGTransformNode +{ +public: + MonoSGNode(QQuickItem *owner) + : m_owner(owner) + { + } + + void deleteContent() + { + QSGNode *subnode = firstChild(); + while (subnode) { + // We can't delete the node now as it might be in the preprocess list + // It will be deleted in the next preprocess + m_nodes_to_delete.append(subnode); + subnode = subnode->nextSibling(); + } + removeAllChildNodes(); + } + + void preprocess() + { + while (m_nodes_to_delete.count()) + delete m_nodes_to_delete.takeLast(); + } + + void setLatinText(const QString &text, const QFont &font, const QColor &color) { + QRawFont raw_font = QRawFont::fromFont(font, QFontDatabase::Latin); + + if (raw_font != m_raw_font) { + m_raw_font = raw_font; + m_positions.clear(); + } + + if (m_positions.size() < text.size()) { + qreal x_pos = 0; + qreal max_char_width = raw_font.averageCharWidth(); + qreal ascent = raw_font.ascent(); + if (m_positions.size()) + x_pos = m_positions.last().x() + max_char_width; + int to_add = text.size() - m_positions.size(); + for (int i = 0; i < to_add; i++) { + m_positions << QPointF(x_pos, ascent); + x_pos += max_char_width; + } + } + + deleteContent(); + QSGRenderContext *sgr = QQuickItemPrivate::get(m_owner)->sceneGraphRenderContext(); + QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr); + node->setOwnerElement(m_owner); + node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern); + node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern); + node->setStyle(QQuickText::Normal); + + node->setColor(color); + QGlyphRun glyphrun; + glyphrun.setRawFont(raw_font); + glyphrun.setGlyphIndexes(raw_font.glyphIndexesForString(text)); + + glyphrun.setPositions(m_positions); + node->setGlyphs(QPointF(0, raw_font.ascent()), glyphrun); + node->update(); + appendChildNode(node); + } + + void setUnicodeText(const QString &text, const QFont &font, const QColor &color) + { + deleteContent(); + QRawFont raw_font = QRawFont::fromFont(font, QFontDatabase::Latin); + qreal line_width = raw_font.averageCharWidth() * text.size(); + QSGRenderContext *sgr = QQuickItemPrivate::get(m_owner)->sceneGraphRenderContext(); + QTextLayout layout(text,font); + layout.beginLayout(); + QTextLine line = layout.createLine(); + line.setLineWidth(line_width); + //Q_ASSERT(!layout.createLine().isValid()); + layout.endLayout(); + QList glyphRuns = line.glyphRuns(); + qreal xpos = 0; + for (int i = 0; i < glyphRuns.size(); i++) { + QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr); + node->setOwnerElement(m_owner); + node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern); + node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern); + node->setGlyphs(QPointF(xpos, raw_font.ascent()), glyphRuns.at(i)); + node->setStyle(QQuickText::Normal); + node->setColor(color); + xpos += raw_font.averageCharWidth() * glyphRuns.at(i).positions().size(); + node->update(); + appendChildNode(node); + } + } +private: + QQuickItem *m_owner; + QVector m_positions; + QLinkedList m_nodes_to_delete; + QRawFont m_raw_font; +}; + +MonoText::MonoText(QQuickItem *parent) + : QQuickItem(parent) + , m_color_changed(false) + , m_latin(true) + , m_old_latin(true) +{ + setFlag(ItemHasContents, true); +} + +MonoText::~MonoText() +{ + +} + +QString MonoText::text() const +{ + return m_text; +} + +void MonoText::setText(const QString &text) +{ + if (m_text != text) { + m_text = text; + emit textChanged(); + polish(); + } +} + +QFont MonoText::font() const +{ + return m_font; +} + +void MonoText::setFont(const QFont &font) +{ + if (font != m_font) { + m_font = font; + emit fontChanged(); + polish(); + } +} + +QColor MonoText::color() const +{ + return m_color; +} + +void MonoText::setColor(const QColor &color) +{ + if (m_color != color) { + m_color = color; + emit colorChanged(); + update(); + } +} + +qreal MonoText::paintedWidth() const +{ + return implicitWidth(); +} + +qreal MonoText::paintedHeight() const +{ + return implicitHeight(); +} + +bool MonoText::latin() const +{ + return m_latin; +} + +void MonoText::setLatin(bool latin) +{ + if (latin == m_latin) + return; + + m_latin = latin; + emit latinChanged(); +} + +QSGNode *MonoText::updatePaintNode(QSGNode *old, UpdatePaintNodeData *) +{ + if (m_text.size() == 0 || m_text.trimmed().size() == 0) { + delete old; + return 0; + } + MonoSGNode *node = static_cast(old); + if (!node) { + node = new MonoSGNode(this); + } + + if (m_latin) { + node->setLatinText(m_text, m_font, m_color); + } else { + node->setUnicodeText(m_text, m_font, m_color); + } + + return node; +} + +void MonoText::updatePolish() +{ + QRawFont raw_font = QRawFont::fromFont(m_font, QFontDatabase::Latin); + + qreal height = raw_font.descent() + raw_font.ascent() + raw_font.lineThickness(); + qreal width = raw_font.averageCharWidth() * m_text.size(); + + bool emit_text_width_changed = width != implicitWidth(); + bool emit_text_height_changed = height != implicitHeight(); + setImplicitSize(width, height); + + if (emit_text_width_changed) + emit paintedWidthChanged(); + if (emit_text_height_changed) + emit paintedHeightChanged(); + + update(); +} diff --git a/yat/yat_declarative/mono_text.h b/yat/yat_declarative/mono_text.h new file mode 100644 index 0000000..49149bf --- /dev/null +++ b/yat/yat_declarative/mono_text.h @@ -0,0 +1,81 @@ +/****************************************************************************** +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +******************************************************************************/ + +#ifndef MONO_TEXT_H +#define MONO_TEXT_H + +#include +#include + +class MonoText : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedWidthChanged) + Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedHeightChanged) + Q_PROPERTY(bool latin READ latin WRITE setLatin NOTIFY latinChanged); +public: + MonoText(QQuickItem *parent=0); + ~MonoText(); + + QString text() const; + void setText(const QString &text); + + QFont font() const; + void setFont(const QFont &font); + + QColor color() const; + void setColor(const QColor &color); + + qreal paintedWidth() const; + qreal paintedHeight() const; + + bool latin() const; + void setLatin(bool latin); + +signals: + void textChanged(); + void fontChanged(); + void colorChanged(); + void paintedWidthChanged(); + void paintedHeightChanged(); + void latinChanged(); +protected: + QSGNode *updatePaintNode(QSGNode *old, UpdatePaintNodeData *data) Q_DECL_OVERRIDE; + void updatePolish() Q_DECL_OVERRIDE; +private: + Q_DISABLE_COPY(MonoText); + void updateSize(); + + QString m_text; + QFont m_font; + QColor m_color; + bool m_color_changed; + bool m_latin; + bool m_old_latin; + QSizeF m_text_size; +}; + +#endif diff --git a/yat/yat_declarative/object_destruct_item.cpp b/yat/yat_declarative/object_destruct_item.cpp new file mode 100644 index 0000000..4f48280 --- /dev/null +++ b/yat/yat_declarative/object_destruct_item.cpp @@ -0,0 +1,55 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#include "object_destruct_item.h" + +ObjectDestructItem::ObjectDestructItem(QQuickItem *parent) + : QQuickItem(parent) + , m_object(0) +{ +} + +QObject *ObjectDestructItem::objectHandle() const +{ + return m_object; +} + +void ObjectDestructItem::setObjectHandle(QObject *object) +{ + bool emit_changed = m_object != object; + if (m_object) { + m_object->disconnect(this); + } + + m_object = object; + connect(m_object, SIGNAL(destroyed()), this, SLOT(objectDestroyed())); + + if (emit_changed) + emit objectHandleChanged(); +} + +void ObjectDestructItem::objectDestroyed() +{ + delete this; +} + diff --git a/yat/yat_declarative/object_destruct_item.h b/yat/yat_declarative/object_destruct_item.h new file mode 100644 index 0000000..fb74691 --- /dev/null +++ b/yat/yat_declarative/object_destruct_item.h @@ -0,0 +1,52 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +#ifndef OBJECT_DESTRUCT_ITEM_H +#define OBJECT_DESTRUCT_ITEM_H + +#include +#include + +class ObjectDestructItem : public QQuickItem +{ + Q_OBJECT + + Q_PROPERTY(QObject *objectHandle READ objectHandle WRITE setObjectHandle NOTIFY objectHandleChanged) + +public: + ObjectDestructItem(QQuickItem *parent = 0); + + QObject *objectHandle() const; + void setObjectHandle(QObject *line); + +signals: + void objectHandleChanged(); + +private slots: + void objectDestroyed(); + +private: + QObject *m_object; +}; + +#endif //OBJECT_DESTRUCT_ITEM_H diff --git a/yat/yat_declarative/qml/yat_declarative/HighlightArea.qml b/yat/yat_declarative/qml/yat_declarative/HighlightArea.qml new file mode 100644 index 0000000..3a81c9f --- /dev/null +++ b/yat/yat_declarative/qml/yat_declarative/HighlightArea.qml @@ -0,0 +1,104 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +import QtQuick 2.0 + +Item { + id: highlightArea + + property real characterWidth: 0 + property real characterHeight: 0 + property int screenWidth: 0 + + property int startX + property int startY + + property int endX + property int endY + + property color color: "grey" + + y: startY * characterHeight + width: parent.width + height: (endY - startY + 1) * characterHeight + + opacity: 0.8 + + Rectangle { + id: begginning_rectangle + color: parent.color + opacity: parent.opacity + y:0 + height: characterHeight + } + + Rectangle { + id: middle_rectangle + color: parent.color + opacity: parent.opacity + width: parent.width + x: 0 + anchors.top: begginning_rectangle.bottom + + } + + Rectangle { + id: end_rectangle + color: parent.color + opacity: parent.opacity + x: 0 + height: characterHeight + anchors.top: middle_rectangle.bottom + } + + onCharacterWidthChanged: calculateRectangles(); + onCharacterHeightChanged: calculateRectangles(); + onScreenWidthChanged: calculateRectangles(); + + onStartXChanged: calculateRectangles(); + onStartYChanged: calculateRectangles(); + onEndXChanged: calculateRectangles(); + onEndYChanged: calculateRectangles(); + + function calculateRectangles() { + highlightArea.y = startY * characterHeight; + begginning_rectangle.x = startX * characterWidth; + if (startY === endY) { + middle_rectangle.visible = false; + end_rectangle.visible = false + begginning_rectangle.width = (endX - startX) * characterWidth; + } else { + begginning_rectangle.width = (screenWidth - startX) * characterWidth; + if (startY === endY - 1) { + middle_rectangle.height = 0; + middle_rectangle.visible = false; + }else { + middle_rectangle.visible = true; + middle_rectangle.height = (endY - startY - 1) * characterHeight; + } + end_rectangle.visible = true; + end_rectangle.width = endX * characterWidth; + } + } + +} diff --git a/yat/yat_declarative/qml/yat_declarative/TerminalCursor.qml b/yat/yat_declarative/qml/yat_declarative/TerminalCursor.qml new file mode 100644 index 0000000..a37e682 --- /dev/null +++ b/yat/yat_declarative/qml/yat_declarative/TerminalCursor.qml @@ -0,0 +1,66 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +import QtQuick 2.0 + +import org.yat 1.0 + +ObjectDestructItem { + id: cursor + + property real fontHeight + property real fontWidth + + height: fontHeight + width: fontWidth + x: objectHandle.x * fontWidth + y: objectHandle.y * fontHeight + z: 1.1 + + visible: objectHandle.visible + + ShaderEffect { + anchors.fill: parent + + property variant source: fragmentSource + + fragmentShader: + "uniform lowp float qt_Opacity;" + + "uniform sampler2D source;" + + "varying highp vec2 qt_TexCoord0;" + + + "void main() {" + + " lowp vec4 color = texture2D(source, qt_TexCoord0 ) * qt_Opacity;" + + " gl_FragColor = vec4(1.0 - color.r, 1.0 - color.g, 1.0 - color.b, color.a);" + + "}" + + ShaderEffectSource { + id: fragmentSource + sourceItem: background + live: true + + sourceRect: Qt.rect(cursor.x,cursor.y,cursor.width,cursor.height); + } + } +} + diff --git a/yat/yat_declarative/qml/yat_declarative/TerminalScreen.qml b/yat/yat_declarative/qml/yat_declarative/TerminalScreen.qml new file mode 100644 index 0000000..fac7c03 --- /dev/null +++ b/yat/yat_declarative/qml/yat_declarative/TerminalScreen.qml @@ -0,0 +1,285 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Controls 1.1 + +import org.yat 1.0 + +TerminalScreen { + id: screenItem + + property font font + property real fontWidth: fontMetricText.paintedWidth + property real fontHeight: fontMetricText.paintedHeight + + property var lineComponent : Qt.createComponent("TerminalLine.qml") + property var textComponent : Qt.createComponent("TerminalText.qml") + property var cursorComponent : Qt.createComponent("TerminalCursor.qml") + + font.family: "menlo" + focus: true + + Action { + id: copyAction + shortcut: "Ctrl+Shift+C" + onTriggered: screen.selection.sendToClipboard() + } + Action { + id: paseAction + shortcut: "Ctrl+Shift+V" + onTriggered: screen.selection.pasteFromClipboard() + } + + onActiveFocusChanged: { + if (activeFocus) { + Qt.inputMethod.show(); + } + } + + Keys.onPressed: { + if (event.text === "?") { + terminal.screen.printScreen() + } + } + + Text { + id: fontMetricText + text: "B" + font: parent.font + visible: false + textFormat: Text.PlainText + } + + Flickable { + id: flickable + anchors.top: parent.top + anchors.left: parent.left + contentWidth: width + contentHeight: textContainer.height + interactive: true + flickableDirection: Flickable.VerticalFlick + contentY: ((screen.contentHeight - screen.height) * screenItem.fontHeight) + + Item { + id: textContainer + width: parent.width + height: screen.contentHeight * screenItem.fontHeight + Rectangle { + id: background + anchors.fill: parent + color: terminal.screen.defaultBackgroundColor + } + + HighlightArea { + characterHeight: fontHeight + characterWidth: fontWidth + screenWidth: terminalWindow.width + + startX: screen.selection.startX + startY: screen.selection.startY + + endX: screen.selection.endX + endY: screen.selection.endY + + visible: screen.selection.enable + } + } + + onContentYChanged: { + if (!atYEnd) { + var top_line = Math.floor(Math.max(contentY,0) / screenItem.fontHeight); + screen.ensureVisiblePages(top_line); + } + } + } + + Connections { + id: connections + + target: terminal.screen + + onFlash: { + flashAnimation.start() + } + + onReset: { + resetScreenItems(); + } + + onTextCreated: { + var textSegment = textComponent.createObject(screenItem, + { + "parent" : background, + "objectHandle" : text, + "font" : screenItem.font, + "fontWidth" : screenItem.fontWidth, + "fontHeight" : screenItem.fontHeight, + }) + } + + onCursorCreated: { + if (cursorComponent.status != Component.Ready) { + console.log(cursorComponent.errorString()); + return; + } + var cursorVariable = cursorComponent.createObject(screenItem, + { + "parent" : textContainer, + "objectHandle" : cursor, + "fontWidth" : screenItem.fontWidth, + "fontHeight" : screenItem.fontHeight, + }) + } + + onRequestHeightChange: { + terminalWindow.height = newHeight * screenItem.fontHeight; + terminalWindow.contentItem.height = newHeight * screenItem.fontHeight; + } + + onRequestWidthChange: { + terminalWindow.width = newWidth * screenItem.fontWidth; + terminalWindow.contentItem.width = newWidth * screenItem.fontWidth; + } + } + + onFontChanged: { + setTerminalHeight(); + setTerminalWidth(); + } + + onWidthChanged: { + setTerminalWidth(); + } + onHeightChanged: { + setTerminalHeight(); + } + Component.onCompleted: { + setTerminalWidth(); + setTerminalHeight(); + } + + function setTerminalWidth() { + if (fontWidth > 0) { + var pty_width = Math.floor(width / fontWidth); + flickable.width = pty_width * fontWidth; + screen.width = pty_width; + } + } + + function setTerminalHeight() { + if (fontHeight > 0) { + var pty_height = Math.floor(height / fontHeight); + flickable.height = pty_height * fontHeight; + screen.height = pty_height; + } + } + + Rectangle { + id: flash + z: 1.2 + anchors.fill: parent + color: "grey" + opacity: 0 + SequentialAnimation { + id: flashAnimation + NumberAnimation { + target: flash + property: "opacity" + to: 1 + duration: 75 + } + NumberAnimation { + target: flash + property: "opacity" + to: 0 + duration: 75 + } + } + } + + MouseArea { + id:mousArea + + property int drag_start_x + property int drag_start_y + + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.MiddleButton + onPressed: { + if (mouse.button == Qt.LeftButton) { + hoverEnabled = true; + var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); + var character = Math.floor((transformed_mouse.x / fontWidth)); + var line = Math.floor(transformed_mouse.y / fontHeight); + var start = Qt.point(character,line); + drag_start_x = character; + drag_start_y = line; + screen.selection.startX = character; + screen.selection.startY = line; + screen.selection.endX = character; + screen.selection.endY = line; + } + } + + onPositionChanged: { + var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); + var character = Math.floor(transformed_mouse.x / fontWidth); + var line = Math.floor(transformed_mouse.y / fontHeight); + var current_pos = Qt.point(character,line); + if (line < drag_start_y || (line === drag_start_y && character < drag_start_x)) { + screen.selection.startX = character; + screen.selection.startY = line; + screen.selection.endX = drag_start_x; + screen.selection.endY = drag_start_y; + }else { + screen.selection.startX = drag_start_x; + screen.selection.startY = drag_start_y; + screen.selection.endX = character; + screen.selection.endY = line; + } + } + + onReleased: { + if (mouse.button == Qt.LeftButton) { + hoverEnabled = false; + screen.selection.sendToSelection(); + } + } + + onClicked: { + if (mouse.button == Qt.MiddleButton) { + screen.pasteFromSelection(); + } + } + + onDoubleClicked: { + if (mouse.button == Qt.LeftButton) { + var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); + var character = Math.floor(transformed_mouse.x / fontWidth); + var line = Math.floor(transformed_mouse.y / fontHeight); + screen.doubleClicked(Qt.point(character,line)); + } + } + } +} diff --git a/yat/yat_declarative/qml/yat_declarative/TerminalText.qml b/yat/yat_declarative/qml/yat_declarative/TerminalText.qml new file mode 100644 index 0000000..1ac5294 --- /dev/null +++ b/yat/yat_declarative/qml/yat_declarative/TerminalText.qml @@ -0,0 +1,81 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +import QtQuick 2.0 + +import org.yat 1.0 + +ObjectDestructItem { + id: textItem + property font font + property real fontWidth + property real fontHeight + + y: objectHandle.line * fontHeight; + x: objectHandle.index * fontWidth; + + width: textElement.paintedWidth + height: textElement.paintedHeight + + visible: objectHandle.visible + + Rectangle { + anchors.fill: parent + color: objectHandle.backgroundColor + + MonoText { + id: textElement + anchors.fill: parent + text: objectHandle.text + color: objectHandle.foregroundColor + font.family: textItem.font.family + font.pixelSize: textItem.font.pixelSize + font.pointSize: textItem.font.pointSize + font.bold: objectHandle.bold + font.underline: objectHandle.underline + latin: objectHandle.latin + + SequentialAnimation { + running: objectHandle.blinking + loops: Animation.Infinite + onRunningChanged: { + if (running === false) + textElement.opacity = 1 + } + NumberAnimation { + target: textElement + property: "opacity" + to: 0 + duration: 250 + } + NumberAnimation { + target: textElement + property: "opacity" + to: 1 + duration: 250 + } + } + } + } + +} diff --git a/yat/yat_declarative/qml/yat_declarative/main.qml b/yat/yat_declarative/qml/yat_declarative/main.qml new file mode 100644 index 0000000..a63c800 --- /dev/null +++ b/yat/yat_declarative/qml/yat_declarative/main.qml @@ -0,0 +1,37 @@ +/******************************************************************************* +* Copyright (c) 2013 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +*******************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Window 2.0 + +Window { + id: terminalWindow + TerminalScreen { + id: terminal + anchors.fill: parent + Component.onCompleted: terminalWindow.visible = true + } + width: 800 + height: 600 + color: terminal.screen.defaultBackgroundColor +} diff --git a/yat/yat_declarative/qml_sources.qrc b/yat/yat_declarative/qml_sources.qrc new file mode 100644 index 0000000..4b9427e --- /dev/null +++ b/yat/yat_declarative/qml_sources.qrc @@ -0,0 +1,9 @@ + + + qml/yat_declarative/main.qml + qml/yat_declarative/TerminalScreen.qml + qml/yat_declarative/TerminalText.qml + qml/yat_declarative/TerminalCursor.qml + qml/yat_declarative/HighlightArea.qml + + diff --git a/yat/yat_declarative/register_qml_types.cpp b/yat/yat_declarative/register_qml_types.cpp new file mode 100644 index 0000000..94e045d --- /dev/null +++ b/yat/yat_declarative/register_qml_types.cpp @@ -0,0 +1,22 @@ +#include "register_qml_types.h" + +#include + +#include "terminal_screen.h" +#include "object_destruct_item.h" +#include "screen.h" +#include "text.h" +#include "cursor.h" +#include "mono_text.h" +#include "selection.h" + +void register_qml_types() +{ + qmlRegisterType("org.yat", 1, 0, "TerminalScreen"); + qmlRegisterType("org.yat", 1, 0, "ObjectDestructItem"); + qmlRegisterType("org.yat", 1, 0, "MonoText"); + qmlRegisterType(); + qmlRegisterType(); + qmlRegisterType(); + qmlRegisterType(); +} diff --git a/yat/yat_declarative/register_qml_types.h b/yat/yat_declarative/register_qml_types.h new file mode 100644 index 0000000..5b036c6 --- /dev/null +++ b/yat/yat_declarative/register_qml_types.h @@ -0,0 +1,6 @@ +#ifndef REGISTER_QML_TYPES_H +#define REGISTER_QML_TYPES_H + +void register_qml_types(); + +#endif // REGISTER_QML_TYPES_H diff --git a/yat/yat_declarative/terminal_screen.cpp b/yat/yat_declarative/terminal_screen.cpp new file mode 100644 index 0000000..1000cb6 --- /dev/null +++ b/yat/yat_declarative/terminal_screen.cpp @@ -0,0 +1,65 @@ +/************************************************************************************************** +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +* associated documentation files (the "Software"), to deal in the Software without restriction, +* including without limitation the rights to use, copy, modify, merge, publish, distribute, +* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +* OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +* +***************************************************************************************************/ + +#include "terminal_screen.h" + +TerminalScreen::TerminalScreen(QQuickItem *parent) + : QQuickItem(parent) + , m_screen(new Screen(this)) +{ + setFlag(QQuickItem::ItemAcceptsInputMethod); +} + +Screen *TerminalScreen::screen() const +{ + return m_screen; +} + +QVariant TerminalScreen::inputMethodQuery(Qt::InputMethodQuery query) const +{ + switch (query) { + case Qt::ImEnabled: + return QVariant(true); + case Qt::ImHints: + return QVariant(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText); + default: + return QVariant(); + } +} + +void TerminalScreen::inputMethodEvent(QInputMethodEvent *event) +{ + QString commitString = event->commitString(); + if (commitString.isEmpty()) { + return; + } + + Qt::Key key = Qt::Key_unknown; + if (commitString == " ") { + key = Qt::Key_Space; // screen requires + } + + m_screen->sendKey(commitString, key, 0); +} + +void TerminalScreen::keyPressEvent(QKeyEvent *event) +{ + m_screen->sendKey(event->text(), Qt::Key(event->key()), event->modifiers()); +} diff --git a/yat/yat_declarative/terminal_screen.h b/yat/yat_declarative/terminal_screen.h new file mode 100644 index 0000000..eb0711c --- /dev/null +++ b/yat/yat_declarative/terminal_screen.h @@ -0,0 +1,54 @@ +/****************************************************************************** +* Copyright (c) 2012 Jørgen Lind +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +* +******************************************************************************/ + +#ifndef TERMINALITEM_H +#define TERMINALITEM_H + +#include +#include +#include +#include + +#include "screen.h" + +class TerminalScreen : public QQuickItem +{ + Q_OBJECT + + Q_PROPERTY(Screen *screen READ screen CONSTANT) +public: + TerminalScreen(QQuickItem *parent = 0); + + Screen *screen() const; + + QVariant inputMethodQuery(Qt::InputMethodQuery query) const; + +protected: + void inputMethodEvent(QInputMethodEvent *event); + void keyPressEvent(QKeyEvent *event); + +private: + Screen *m_screen; +}; + +#endif // TERMINALITEM_H diff --git a/yat/yat_declarative/yat_declarative.pro b/yat/yat_declarative/yat_declarative.pro new file mode 100644 index 0000000..6159a7e --- /dev/null +++ b/yat/yat_declarative/yat_declarative.pro @@ -0,0 +1,18 @@ +QT += gui quick +TARGET = yat + +include(../backend/backend.pri) + +INCLUDEPATH += $$PWD + +SOURCES += $$PWD/terminal_screen.cpp \ + $$PWD/object_destruct_item.cpp \ + $$PWD/register_qml_types.cpp \ + $$PWD/mono_text.cpp \ + +HEADERS += \ + $$PWD/terminal_screen.h \ + $$PWD/object_destruct_item.h \ + $$PWD/register_qml_types.h \ + $$PWD/mono_text.h \ +