aboutsummaryrefslogtreecommitdiff
path: root/EmbeddedTerminal.qml
blob: e02ba610f30bcdec64f1d3370ae856581c396e6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import QtQuick 2.0
import QMLTermWidget 1.0
import QtQuick.Controls 1.2

Item {
	id: embeddedTerminal
	property string program
	property string workingDirectory
	property int columns
	property int lines

	width: container.width
	height: container.height

	function focus() { terminal.forceActiveFocus() }

	Row {
		id: container

		Rectangle {
			id: highlighter

			width: 10
			height: terminal.height

			color: "#aadb0f"

			Behavior on opacity {
				NumberAnimation {
					duration: 300
					easing.type: Easing.OutCubic
				}
			}

			function focus()   { opacity = 1 }
			function unfocus() { opacity = 0 }
		}

		Rectangle {
			width: terminal.width
			height: terminal.height

			color: "#ffffff"

			QMLTermWidget {
				id: terminal

				font.family: "Monospace"
				font.pointSize: 8

				width: fontMetrics.width * embeddedTerminal.columns
				height: fontMetrics.height * embeddedTerminal.lines

				session: QMLTermSession {
					initialWorkingDirectory: embeddedTerminal.workingDirectory

					shellProgram: {
						return (embeddedTerminal.program).split(" ")[0];
					}

					shellProgramArgs: {
						var elements = (embeddedTerminal.program).split(" ");
						elements.shift();

						return elements;
					}
				}

				MouseArea {
					anchors.fill: parent
					acceptedButtons: Qt.LeftButton
					onClicked: parent.forceActiveFocus();
					onWheel: { }
				}

				onTermGetFocus: highlighter.focus()
				onTermLostFocus: highlighter.unfocus()

				Component.onCompleted: {
					terminal.forceActiveFocus();
					session.startShellProgram();
				}
			}
		}
	}
}