Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Games
KMuddy
Commits
7afa8ee4
Commit
7afa8ee4
authored
Jul 07, 2018
by
Tomas Mecir
Browse files
Delete old lines when the scrollback limit has been reached.
parent
825ab863
Changes
3
Hide whitespace changes
Inline
Side-by-side
libs/cconsole.cpp
View file @
7afa8ee4
...
...
@@ -28,6 +28,7 @@
#include <QGraphicsItemGroup>
#include <QGraphicsTextItem>
#include <QScrollBar>
#include <QTextBlock>
#include <QTextCursor>
#include <QTextDocument>
...
...
@@ -111,6 +112,7 @@ class cConsole::Private {
cScrollTextGroup
*
scrollTextGroup
;
QTextDocument
*
text
;
int
historySize
;
QColor
bgcolor
;
QFont
font
;
int
sess
;
...
...
@@ -130,6 +132,7 @@ cConsole::cConsole(QWidget *parent) : QGraphicsView(parent) {
d
->
charHeight
=
12
;
d
->
wantNewLine
=
false
;
d
->
atBottom
=
true
;
d
->
historySize
=
1000
;
setHorizontalScrollBarPolicy
(
Qt
::
ScrollBarAlwaysOff
);
setVerticalScrollBarPolicy
(
Qt
::
ScrollBarAlwaysOn
);
...
...
@@ -307,12 +310,8 @@ void cConsole::dumpBuffer (bool fromcurrent, QFile &file, char dumpType) {
// TODO
}
void
cConsole
::
tryUpdateHistorySize
()
{
// TODO
}
void
cConsole
::
setInitialHistorySize
(
int
size
)
{
// TODO
void
cConsole
::
setHistorySize
(
int
size
)
{
d
->
historySize
=
size
;
}
QStringList
cConsole
::
words
(
QString
prefix
,
int
minLength
)
{
...
...
@@ -336,6 +335,10 @@ void cConsole::addText (cTextChunk *chunk) {
addNewText
(
chunk
,
false
);
}
int
cConsole
::
totalLines
()
{
return
d
->
text
->
lineCount
();
}
void
cConsole
::
addNewText
(
cTextChunk
*
chunk
,
bool
endTheLine
)
{
QTextCursor
cursor
(
d
->
text
);
...
...
@@ -351,6 +354,22 @@ void cConsole::addNewText (cTextChunk *chunk, bool endTheLine)
if
(
endTheLine
)
d
->
wantNewLine
=
true
;
// TODO - if the buffer is full, remove old blocks/lines
while
(
totalLines
()
>
d
->
historySize
)
{
// check the height of the first block; if removing it won't put us below the history limit, remove it
QTextBlock
fblock
=
d
->
text
->
firstBlock
();
int
flines
=
fblock
.
lineCount
();
if
(
totalLines
()
-
flines
<
d
->
historySize
)
break
;
int
fheight
=
d
->
text
->
documentLayout
()
->
blockBoundingRect
(
fblock
).
height
();
cursor
=
QTextCursor
(
fblock
);
cursor
.
select
(
QTextCursor
::
BlockUnderCursor
);
cursor
.
movePosition
(
QTextCursor
::
NextCharacter
,
QTextCursor
::
KeepAnchor
);
// need to move, otherwise the empty block is kept
cursor
.
removeSelectedText
();
// scroll accordingly if needed
QScrollBar
*
bar
=
verticalScrollBar
();
if
(
!
d
->
atBottom
)
bar
->
setValue
(
bar
->
value
()
-
fheight
);
}
fixupOutput
();
}
...
...
libs/cconsole.h
View file @
7afa8ee4
...
...
@@ -75,9 +75,10 @@ public:
void
forceEmitSize
();
/** dump all history buffer to that file */
void
dumpBuffer
(
bool
fromcurrent
,
QFile
&
file
,
char
dumpType
);
void
tryUpdateHistorySize
();
void
setInitialHistorySize
(
int
size
);
void
setHistorySize
(
int
size
);
/** How many lines in total does the console have currently? */
int
totalLines
();
QStringList
words
(
QString
prefix
,
int
minLength
=
3
);
/** clear the widget */
void
clear
();
...
...
libs/coutput.cpp
View file @
7afa8ee4
...
...
@@ -85,7 +85,7 @@ void cOutput::eventNothingHandler (QString event, int /*session*/)
{
if
(
event
==
"global-settings-changed"
)
{
cGlobalSettings
*
gs
=
cGlobalSettings
::
self
();
con
->
set
Initial
HistorySize
(
gs
->
getInt
(
"history-size"
));
con
->
setHistorySize
(
gs
->
getInt
(
"history-size"
));
con
->
setFont
(
gs
->
getFont
(
"console-font"
));
setEchoColor
(
gs
->
getColor
(
"color-"
+
QString
::
number
(
gs
->
getInt
(
"echo-color"
))));
...
...
@@ -98,8 +98,6 @@ void cOutput::eventNothingHandler (QString event, int /*session*/)
//changing font often causes view to move - move to the very bottom
con
->
verticalScrollBar
()
->
setValue
(
con
->
verticalScrollBar
()
->
maximum
());
con
->
tryUpdateHistorySize
();
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment