From kde-core-devel Thu May 31 23:43:09 2001 From: Guillaume Laurent Date: Thu, 31 May 2001 23:43:09 +0000 To: kde-core-devel Subject: PATCH, take 2 , uses BlockArray (was Re: konsole's history : is anyone taking care of it ?) X-MARC-Message: https://marc.info/?l=kde-core-devel&m=99135272011281 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--------------Boundary-00=_XJ48JJJ0S9A9YWNNISWE" --------------Boundary-00=_XJ48JJJ0S9A9YWNNISWE Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit On Monday 28 May 2001 17:16, Stephan Kulow wrote: > If your patch works, put it in (after approval of Chris) and I'll try later > to revive my BlockArray stuff Given that nobody expressed interest in file logging and it looked like a headache to get right (from the user's standpoint, that is, how to select the file name), I went ahead and used your BlockArray instead. I had to make a couple of changes, you might want to check (see in BlockArray::at(size_t i)). The attached patch is simpler (though it carries a lot of #if 0'ed code in case the other history mechanisms are found useful later on). Session management is here. -- Guillaume. http://www.telegraph-road.org --------------Boundary-00=_XJ48JJJ0S9A9YWNNISWE Content-Type: text/x-c++; charset="iso-8859-1"; name="konsole_history_patch_2.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="konsole_history_patch_2.patch" Index: BlockArray.C =================================================================== RCS file: /home/kde/kdebase/konsole/src/BlockArray.C,v retrieving revision 1.2 diff -u -r1.2 BlockArray.C --- BlockArray.C 2000/10/29 23:34:07 1.2 +++ BlockArray.C 2001/05/31 23:36:29 @@ -9,14 +9,18 @@ static int blocksize = 0; BlockArray::BlockArray() - : size(0), lastmap(0), lastblock(0), ion(-1), length(0) + : size(0), + current(-1), + index(-1), + lastmap(0), + lastmap_index(-1), + lastblock(0), ion(-1), + length(0) { - lastmap_index = index = current = size_t(-1); + // lastmap_index = index = current = size_t(-1); if (blocksize == 0) blocksize = ((sizeof(Block) / getpagesize()) + 1) * getpagesize(); - if (!size) - return; } BlockArray::~BlockArray() @@ -29,15 +33,19 @@ { if (!size) return size_t(-1); + + ++current; + if (current >= size) current = 0; - current = ++current % size; int rc; rc = lseek(ion, current * blocksize, SEEK_SET); if (rc < 0) { perror("HistoryBuffer::add.seek"); setHistorySize(0); return size_t(-1); } rc = write(ion, block, blocksize); if (rc < 0) { perror("HistoryBuffer::add.write"); setHistorySize(0); return size_t(-1); } + length++; - if (length>size) - length=size; - index++; + if (length > size) length = size; + + ++index; + delete block; return current; } @@ -69,7 +77,7 @@ return true; } -const Block *BlockArray::at(size_t i) +const Block* BlockArray::at(size_t i) { if (i == index + 1) return lastblock; @@ -77,20 +85,28 @@ if (i == lastmap_index) return lastmap; - if (i > index) + if (i > index) { + kdDebug() << "BlockArray::at() i > index\n"; return 0; - if (index - i >= length) - return 0; - size_t j = (current - (index - i) + (index/size+1)*size) % size; + } + +// if (index - i >= length) { +// kdDebug() << "BlockArray::at() index - i >= length\n"; +// return 0; +// } + size_t j = i; // (current - (index - i) + (index/size+1)*size) % size ; + assert(j < size); unmap(); Block *block = (Block*)mmap(0, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize); if (block == (Block*)-1) { perror("mmap"); return 0; } + lastmap = block; lastmap_index = i; + return block; } @@ -176,7 +192,7 @@ res = fwrite(buffer2, blocksize, 1, fion); if (res != 1) perror("fwrite"); - printf("moving block %d to %d\n", cursor, newpos); + // printf("moving block %d to %d\n", cursor, newpos); } void BlockArray::decreaseBuffer(size_t newsize) Index: Makefile.am =================================================================== RCS file: /home/kde/kdebase/konsole/src/Makefile.am,v retrieving revision 1.65 diff -u -r1.65 Makefile.am --- Makefile.am 2001/03/23 01:05:09 1.65 +++ Makefile.am 2001/05/31 23:36:30 @@ -20,7 +20,7 @@ # libkonsolepart is a part, but konsole.la links directly to it, so we can't # install it under kde_module -libkonsolepart_la_SOURCES = TEPty.C \ +libkonsolepart_la_SOURCES = BlockArray.C TEPty.C \ schema.C \ session.C \ TEWidget.C \ @@ -50,7 +50,7 @@ konsole_la_LDFLAGS = $(all_libraries) -module -avoid-version # konsole executable - has all the sources, doesn't link kparts, saves startup time -konsole_SOURCES = TEPty.C main.C konsole.C schema.C session.C TEWidget.C TEmuVt102.C \ +konsole_SOURCES = BlockArray.C TEPty.C main.C konsole.C schema.C session.C TEWidget.C TEmuVt102.C \ TEScreen.C TEmulation.C TEHistory.C keytrans.C konsole_LDADD = $(LIB_KDEUI) $(LIB_KSYCOCA) $(LIBUTEMPTER) $(LIBUTIL) konsole_LDFLAGS = $(all_libraries) $(KDE_RPATH) Index: TEHistory.C =================================================================== RCS file: /home/kde/kdebase/konsole/src/TEHistory.C,v retrieving revision 1.12 diff -u -r1.12 TEHistory.C --- TEHistory.C 2001/03/17 14:30:42 1.12 +++ TEHistory.C 2001/05/31 23:36:30 @@ -17,6 +17,7 @@ #include #include #include +#include #ifndef HERE #define HERE printf("%s(%d): here\n",__FILE__,__LINE__) @@ -58,6 +59,8 @@ //#define tmpfile xTmpFile +#if 0 + FILE* xTmpFile() { static int fid = 0; @@ -67,72 +70,72 @@ } -// History Buffer /////////////////////////////////////////// +// History File /////////////////////////////////////////// /* - A Row(X) data type which allows adding elements to the end. + A Row(X) data type which allows adding elements to the end. */ -HistoryBuffer::HistoryBuffer() +HistoryFile::HistoryFile() + : ion(-1), + length(0) { - ion = -1; - length = 0; + FILE* tmp = tmpfile(); if (!tmp) { perror("konsole: cannot open temp file.\n"); return; } + ion = dup(fileno(tmp)); if (ion<0) perror("konsole: cannot dup temp file.\n"); + fclose(tmp); } -HistoryBuffer::~HistoryBuffer() +HistoryFile::~HistoryFile() { - setScroll(FALSE); + close(ion); } -void HistoryBuffer::setScroll(bool on) +void HistoryFile::add(const unsigned char* bytes, int len) { - if (on == hasScroll()) return; + int rc = 0; - if (on) - { - assert( ion < 0 ); - assert( length == 0); - FILE* tmp = tmpfile(); if (!tmp) { perror("konsole: cannot open temp file.\n"); return; } - ion = dup(fileno(tmp)); if (ion<0) perror("konsole: cannot dup temp file.\n"); - fclose(tmp); - } - else - { - assert( ion >= 0 ); - close(ion); - ion = -1; - length = 0; - } + rc = lseek(ion,length,SEEK_SET); if (rc < 0) { perror("HistoryFile::add.seek"); return; } + rc = write(ion,bytes,len); if (rc < 0) { perror("HistoryFile::add.write"); return; } + length += rc; } -bool HistoryBuffer::hasScroll() +void HistoryFile::get(unsigned char* bytes, int len, int loc) { - return ion >= 0; -} - -void HistoryBuffer::add(const unsigned char* bytes, int len) -{ int rc; - assert(hasScroll()); - rc = lseek(ion,length,SEEK_SET); if (rc < 0) { perror("HistoryBuffer::add.seek"); setScroll(FALSE); return; } - rc = write(ion,bytes,len); if (rc < 0) { perror("HistoryBuffer::add.write"); setScroll(FALSE); return; } - length += rc; -} + int rc = 0; -void HistoryBuffer::get(unsigned char* bytes, int len, int loc) -{ int rc; - assert(hasScroll()); if (loc < 0 || len < 0 || loc + len > length) fprintf(stderr,"getHist(...,%d,%d): invalid args.\n",len,loc); - rc = lseek(ion,loc,SEEK_SET); if (rc < 0) { perror("HistoryBuffer::get.seek"); setScroll(FALSE); return; } - rc = read(ion,bytes,len); if (rc < 0) { perror("HistoryBuffer::get.read"); setScroll(FALSE); return; } + rc = lseek(ion,loc,SEEK_SET); if (rc < 0) { perror("HistoryFile::get.seek"); return; } + rc = read(ion,bytes,len); if (rc < 0) { perror("HistoryFile::get.read"); return; } } -int HistoryBuffer::len() +int HistoryFile::len() { return length; } + +#endif + +// History Scroll abstract base class ////////////////////////////////////// + + +HistoryScroll::HistoryScroll(HistoryType* t) + : m_histType(t) +{ +} + +HistoryScroll::~HistoryScroll() +{ + delete m_histType; +} + +bool HistoryScroll::hasScroll() +{ + return true; +} -// History Scroll ////////////////////////////////////// +#if 0 +// History Scroll File ////////////////////////////////////// /* The history scroll makes a Row(Row(Cell)) from @@ -145,64 +148,343 @@ at 0 in cells. */ -HistoryScroll::HistoryScroll() +HistoryScrollFile::HistoryScrollFile(const QString &logFileName) + : HistoryScroll(new HistoryTypeFile(logFileName)), + m_logFileName(logFileName) { } -HistoryScroll::~HistoryScroll() +HistoryScrollFile::~HistoryScrollFile() { } -void HistoryScroll::setScroll(bool on) +int HistoryScrollFile::getLines() { - index.setScroll(on); - cells.setScroll(on); -} - -bool HistoryScroll::hasScroll() -{ - return index.hasScroll() && cells.hasScroll(); -} - -int HistoryScroll::getLines() -{ - if (!hasScroll()) return 0; return index.len() / sizeof(int); } -int HistoryScroll::getLineLen(int lineno) +int HistoryScrollFile::getLineLen(int lineno) { - if (!hasScroll()) return 0; return (startOfLine(lineno+1) - startOfLine(lineno)) / sizeof(ca); } -int HistoryScroll::startOfLine(int lineno) +int HistoryScrollFile::startOfLine(int lineno) { if (lineno <= 0) return 0; - if (!hasScroll()) return 0; if (lineno <= getLines()) - { int res; + { int res; index.get((unsigned char*)&res,sizeof(int),(lineno-1)*sizeof(int)); return res; - } + } return cells.len(); } -void HistoryScroll::getCells(int lineno, int colno, int count, ca res[]) +void HistoryScrollFile::getCells(int lineno, int colno, int count, ca res[]) { - assert(hasScroll()); cells.get((unsigned char*)res,count*sizeof(ca),startOfLine(lineno)+colno*sizeof(ca)); } -void HistoryScroll::addCells(ca text[], int count) +void HistoryScrollFile::addCells(ca text[], int count) { - if (!hasScroll()) return; cells.add((unsigned char*)text,count*sizeof(ca)); } -void HistoryScroll::addLine() +void HistoryScrollFile::addLine() { - if (!hasScroll()) return; int locn = cells.len(); index.add((unsigned char*)&locn,sizeof(int)); } + + +// History Scroll Buffer ////////////////////////////////////// +HistoryScrollBuffer::HistoryScrollBuffer(unsigned int maxNbLines) + : HistoryScroll(new HistoryTypeBuffer(maxNbLines)), + m_maxNbLines(maxNbLines), + m_nbLines(0), + m_arrayIndex(0) +{ + m_histBuffer.setAutoDelete(true); + m_histBuffer.resize(maxNbLines); +} + +HistoryScrollBuffer::~HistoryScrollBuffer() +{ +} + +void HistoryScrollBuffer::addCells(ca a[], int count) +{ + //unsigned int nbLines = countLines(bytes, len); + + histline* newLine = new histline; + + newLine->duplicate(a, count); + + ++m_arrayIndex; + if (m_arrayIndex >= m_maxNbLines) m_arrayIndex = 0; + + if (m_nbLines < m_maxNbLines - 1) ++m_nbLines; + + // m_histBuffer.remove(m_arrayIndex); // not necessary + m_histBuffer.insert(m_arrayIndex, newLine); +} + +void HistoryScrollBuffer::addLine() +{ + // ? Do nothing +} + +int HistoryScrollBuffer::getLines() +{ + return m_nbLines; // m_histBuffer.size(); +} + +int HistoryScrollBuffer::getLineLen(int lineno) +{ + if (lineno >= m_maxNbLines) return 0; + + histline *l = m_histBuffer[lineno]; + + return l ? l->size() : 0; +} + + +void HistoryScrollBuffer::getCells(int lineno, int colno, int count, ca res[]) +{ + if (!count) return; + + assert (lineno < m_maxNbLines); + + histline *l = m_histBuffer[lineno]; + + if (!l) { + memset(res, 0, count * sizeof(ca)); + return; + } + + assert(colno < l->size() || count == 0); + + memcpy(res, l->data() + colno, count * sizeof(ca)); +} + +void HistoryScrollBuffer::setMaxNbLines(unsigned int nbLines) +{ + m_maxNbLines = nbLines; + m_histBuffer.resize(m_maxNbLines); +} + +#endif + +// History Scroll None ////////////////////////////////////// + +HistoryScrollNone::HistoryScrollNone() + : HistoryScroll(new HistoryTypeNone()) +{ +} + +HistoryScrollNone::~HistoryScrollNone() +{ +} + +bool HistoryScrollNone::hasScroll() +{ + return false; +} + +int HistoryScrollNone::getLines() +{ + return 0; +} + +int HistoryScrollNone::getLineLen(int lineno) +{ + return 0; +} + +void HistoryScrollNone::getCells(int lineno, int colno, int count, ca res[]) +{ +} + +void HistoryScrollNone::addCells(ca a[], int count) +{ +} + +void HistoryScrollNone::addLine() +{ +} + +// History Scroll BlockArray ////////////////////////////////////// + +HistoryScrollBlockArray::HistoryScrollBlockArray(size_t size) + : HistoryScroll(new HistoryTypeBlockArray(size)) +{ + m_lineLengths.setAutoDelete(true); + m_blockArray.setSize(size); +} + +HistoryScrollBlockArray::~HistoryScrollBlockArray() +{ +} + +int HistoryScrollBlockArray::getLines() +{ +// kdDebug() << "HistoryScrollBlockArray::getLines() : " +// << m_lineLengths.count() << endl; + + return m_lineLengths.count(); +} + +int HistoryScrollBlockArray::getLineLen(int lineno) +{ + size_t *pLen = m_lineLengths[lineno]; + size_t res = pLen ? *pLen : 0; + + return res; +} + +void HistoryScrollBlockArray::getCells(int lineno, int colno, int count, ca res[]) +{ + if (!count) return; + + const Block *b = m_blockArray.at(lineno); + + if (!b) { + memset(res, 0, count * sizeof(ca)); // still better than random data + return; + } + + assert(((colno + count) * sizeof(ca)) < ENTRIES); + memcpy(res, b->data + (colno * sizeof(ca)), count * sizeof(ca)); +} + +void HistoryScrollBlockArray::addCells(ca a[], int count) +{ + Block *b = m_blockArray.lastBlock(); + + assert (b); + + // put cells in block's data + assert((count * sizeof(ca)) < ENTRIES); + + memset(b->data, 0, ENTRIES); + + memcpy(b->data, a, count * sizeof(ca)); + b->size = count * sizeof(ca); + + size_t res = m_blockArray.newBlock(); + assert (res > 0); + + // store line length + size_t *pLen = new size_t; + *pLen = count; + + m_lineLengths.replace(m_blockArray.getCurrent(), pLen); + +} + +void HistoryScrollBlockArray::addLine() +{ +} + +////////////////////////////////////////////////////////////////////// +// History Types +////////////////////////////////////////////////////////////////////// + +HistoryType::HistoryType() +{ +} + +HistoryType::~HistoryType() +{ +} + +////////////////////////////// + +HistoryTypeNone::HistoryTypeNone() +{ +} + +bool HistoryTypeNone::isOn() const +{ + return false; +} + +HistoryScroll* HistoryTypeNone::getScroll() const +{ + return new HistoryScrollNone(); +} + +unsigned int HistoryTypeNone::getSize() const +{ + return 0; +} + +////////////////////////////// + +HistoryTypeBlockArray::HistoryTypeBlockArray(size_t size) + : m_size(size) +{ +} + +bool HistoryTypeBlockArray::isOn() const +{ + return true; +} + +unsigned int HistoryTypeBlockArray::getSize() const +{ + return m_size; +} + +HistoryScroll* HistoryTypeBlockArray::getScroll() const +{ + return new HistoryScrollBlockArray(m_size); +} + + +#if 0 // Disabled for now + +////////////////////////////// + +HistoryTypeBuffer::HistoryTypeBuffer(unsigned int nbLines) + : m_nbLines(nbLines) +{ +} + +bool HistoryTypeBuffer::isOn() const +{ + return true; +} + +unsigned int HistoryTypeBuffer::getNbLines() const +{ + return m_nbLines; +} + +HistoryScroll* HistoryTypeBuffer::getScroll() const +{ + return new HistoryScrollBuffer(m_nbLines); +} + +////////////////////////////// + +HistoryTypeFile::HistoryTypeFile(const QString& fileName) + : m_fileName(fileName) +{ +} + +bool HistoryTypeFile::isOn() const +{ + return true; +} + +const QString& HistoryTypeFile::getFileName() const +{ + return m_fileName; +} + +HistoryScroll* HistoryTypeFile::getScroll() const +{ + return new HistoryScrollFile(m_fileName); +} + +#endif Index: TEScreen.C =================================================================== RCS file: /home/kde/kdebase/konsole/src/TEScreen.C,v retrieving revision 1.41 diff -u -r1.41 TEScreen.C --- TEScreen.C 2001/03/17 14:30:42 1.41 +++ TEScreen.C 2001/05/31 23:36:32 @@ -61,20 +61,35 @@ /*! creates a `TEScreen' of `lines' lines and `columns' columns. */ -TEScreen::TEScreen(int lines, int columns) -{ - this->lines = lines; - this->columns = columns; - - // we add +1 here as under some weired circumstances konsole crashes - // reading out of bound. As a crash is worse, we afford the minimum - // of added memory - image = (ca*) malloc((lines+1)*columns*sizeof(ca)); - tabstops = NULL; initTabStops(); - cuX = cuY = sa_cu_re = cu_re = sa_cu_fg = cu_fg = sa_cu_bg = cu_bg = 0; +TEScreen::TEScreen(int l, int c) + : lines(l), + columns(c), + image(new ca[(lines+1)*columns]), + histCursor(0), + hist(new HistoryScrollNone()), + cuX(0), cuY(0), + cu_fg(0), cu_bg(0), cu_re(0), + tmargin(0), bmargin(0), + tabstops(0), + sel_begin(0), sel_TL(0), sel_BR(0), + ef_fg(0), ef_bg(0), ef_re(0), + sa_cuX(0), sa_cuY(0), + sa_cu_re(0), sa_cu_fg(0), sa_cu_bg(0) +{ + /* + this->lines = lines; + this->columns = columns; + + // we add +1 here as under some weired circumstances konsole crashes + // reading out of bound. As a crash is worse, we afford the minimum + // of added memory + image = (ca*) malloc((lines+1)*columns*sizeof(ca)); + tabstops = NULL; initTabStops(); + cuX = cuY = sa_cu_re = cu_re = sa_cu_fg = cu_fg = sa_cu_bg = cu_bg = 0; - histCursor = 0; - + histCursor = 0; + */ + initTabStops(); clearSelection(); reset(); } @@ -84,8 +99,9 @@ TEScreen::~TEScreen() { - free(image); - if (tabstops) free(tabstops); + delete[] image; + delete[] tabstops; + delete hist; } /* ------------------------------------------------------------------------- */ @@ -421,7 +437,7 @@ newimg[y*new_columns+x].b = image[loc(x,y)].b; newimg[y*new_columns+x].r = image[loc(x,y)].r; } - free(image); + delete[] image; image = newimg; lines = new_lines; columns = new_columns; @@ -512,13 +528,13 @@ ca* merged = (ca*)malloc(lines*columns*sizeof(ca)); ca dft(' ',DEFAULT_FORE_COLOR,DEFAULT_BACK_COLOR,DEFAULT_RENDITION); - for (y = 0; (y < lines) && (y < (hist.getLines()-histCursor)); y++) + for (y = 0; (y < lines) && (y < (hist->getLines()-histCursor)); y++) { - int len = QMIN(columns,hist.getLineLen(y+histCursor)); + int len = QMIN(columns,hist->getLineLen(y+histCursor)); int yp = y*columns; int yq = (y+histCursor)*columns; - hist.getCells(y+histCursor,0,len,merged+yp); + hist->getCells(y+histCursor,0,len,merged+yp); for (x = len; x < columns; x++) merged[yp+x] = dft; for (x = 0; x < columns; x++) { int p=x + yp; int q=x + yq; @@ -526,13 +542,13 @@ reverseRendition(&merged[p]); // for selection } } - if (lines >= hist.getLines()-histCursor) + if (lines >= hist->getLines()-histCursor) { - for (y = (hist.getLines()-histCursor); y < lines ; y++) + for (y = (hist->getLines()-histCursor); y < lines ; y++) { int yp = y*columns; int yq = (y+histCursor)*columns; - int yr = (y-hist.getLines()+histCursor)*columns; + int yr = (y-hist->getLines()+histCursor)*columns; for (x = 0; x < columns; x++) { int p = x + yp; int q = x + yq; int r = x + yr; merged[p] = image[r]; @@ -548,11 +564,11 @@ for (i = 0; i < n; i++) reverseRendition(&merged[i]); // for reverse display } -// if (getMode(MODE_Cursor) && (cuY+(hist.getLines()-histCursor) < lines)) // cursor visible +// if (getMode(MODE_Cursor) && (cuY+(hist->getLines()-histCursor) < lines)) // cursor visible - int loc_ = loc(cuX, cuY+hist.getLines()-histCursor); + int loc_ = loc(cuX, cuY+hist->getLines()-histCursor); if(getMode(MODE_Cursor) && loc_ < columns*lines) - reverseRendition(&merged[loc(cuX,cuY+(hist.getLines()-histCursor))]); + reverseRendition(&merged[loc(cuX,cuY+(hist->getLines()-histCursor))]); return merged; } @@ -618,8 +634,9 @@ void TEScreen::initTabStops() { - if (tabstops) free(tabstops); - tabstops = (bool*)malloc(columns*sizeof(bool)); + delete[] tabstops; + tabstops = new bool[columns]; + // Arrg! The 1st tabstop has to be one longer than the other. // i.e. the kids start counting from 0 instead of 1. // Other programs might behave correctly. Be aware. @@ -647,7 +664,7 @@ void TEScreen::checkSelection(int from, int to) { if (sel_begin == -1) return; - int scr_TL = loc(0, hist.getLines()); + int scr_TL = loc(0, hist->getLines()); //Clear entire selection if it overlaps region [from, to] if ( (sel_BR > (from+scr_TL) )&&(sel_TL < (to+scr_TL)) ) { @@ -791,7 +808,7 @@ void TEScreen::clearImage(int loca, int loce, char c) { int i; - int scr_TL=loc(0,hist.getLines()); + int scr_TL=loc(0,hist->getLines()); //FIXME: check positions //Clear entire selection if it overlaps region to be moved... @@ -998,7 +1015,7 @@ int *m; // buffer to fill. int s, d; // source index, dest. index. - int hist_BR = loc(0, hist.getLines()); + int hist_BR = loc(0, hist->getLines()); int hY = sel_TL / columns; int hX = sel_TL % columns; int eol; // end of line @@ -1015,9 +1032,9 @@ while (s <= sel_BR) { if (s < hist_BR) - { // get lines from hist.history + { // get lines from hist->history // buffer. - eol = hist.getLineLen(hY); + eol = hist->getLineLen(hY); if ((hY == (sel_BR / columns)) && (eol >= (sel_BR % columns))) @@ -1027,7 +1044,7 @@ while (hX < eol) { - m[d++] = hist.getCell(hY, hX++).c; + m[d++] = hist->getCell(hY, hX++).c; s++; } @@ -1176,11 +1193,11 @@ while (end >= 0 && image[end] == dft) end -= 1; - hist.addCells(image,end+1); - hist.addLine(); + hist->addCells(image,end+1); + hist->addLine(); // adjust history cursor - histCursor += (hist.getLines()-1 == histCursor); + histCursor += (hist->getLines()-1 == histCursor); } if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround @@ -1198,17 +1215,23 @@ int TEScreen::getHistLines() { - return hist.getLines(); + return hist->getLines(); } -void TEScreen::setScroll(bool on) +void TEScreen::setScroll(const HistoryType& t) { histCursor = 0; clearSelection(); - hist.setScroll(on); + delete hist; + hist = t.getScroll(); } bool TEScreen::hasScroll() +{ + return hist->hasScroll(); +} + +const HistoryType& TEScreen::getScroll() { - return hist.hasScroll(); + return hist->getType(); } Index: TEmulation.C =================================================================== RCS file: /home/kde/kdebase/konsole/src/TEmulation.C,v retrieving revision 1.21 diff -u -r1.21 TEmulation.C --- TEmulation.C 2001/03/19 14:37:37 1.21 +++ TEmulation.C 2001/05/31 23:36:33 @@ -92,19 +92,21 @@ /*! */ -TEmulation::TEmulation(TEWidget* gui) -: decoder(0) +TEmulation::TEmulation(TEWidget* w) +: gui(w), + scr(0), + connected(false), + codec(0), + decoder(0), + keytrans(0), + bulk_nlcnt(0), + bulk_incnt(0) { - this->gui = gui; screen[0] = new TEScreen(gui->Lines(),gui->Columns()); screen[1] = new TEScreen(gui->Lines(),gui->Columns()); scr = screen[0]; - bulk_nlcnt = 0; // reset bulk newline counter - bulk_incnt = 0; // reset bulk counter - connected = FALSE; - QObject::connect(&bulk_timer, SIGNAL(timeout()), this, SLOT(showBulk()) ); QObject::connect(gui,SIGNAL(changedImageSizeSignal(int,int)), this,SLOT(onImageSizeChange(int,int))); @@ -141,16 +143,17 @@ scr = screen[n&1]; } -void TEmulation::setHistory(bool on) +void TEmulation::setHistory(const HistoryType& t) { - screen[0]->setScroll(on); + screen[0]->setScroll(t); + if (!connected) return; showBulk(); } -bool TEmulation::history() +const HistoryType& TEmulation::history() { - return screen[0]->hasScroll(); + return screen[0]->getScroll(); } void TEmulation::setCodec(int c) Index: konsole.C =================================================================== RCS file: /home/kde/kdebase/konsole/src/konsole.C,v retrieving revision 1.126 diff -u -r1.126 konsole.C --- konsole.C 2001/05/23 00:24:38 1.126 +++ konsole.C 2001/05/31 23:36:36 @@ -80,6 +80,11 @@ #include #include +#include +#include +#include +#include + #include #include @@ -204,6 +209,7 @@ ,skip_exit_query(false) // used to skip the query when closed by the session management ,b_warnQuit(false) ,alreadyNoticedBackgroundChange_(false) +,m_histSize(0) { //QTime time; //time.start(); @@ -272,6 +278,11 @@ // activate and run first session ////////////////////////////////////////// // FIXME: this slows it down if --type is given, but prevents a crash (malte) se = newSession(co); + if (!m_histSize) + se->setHistory(HistoryTypeNone()); + else + se->setHistory(HistoryTypeBlockArray(m_histSize)); + delete co; //kdDebug()<<"Konsole ctor(): runSession()"<currentSession = se; @@ -434,8 +445,11 @@ // Schema m_options->insertItem( SmallIconSet( "colorize" ), i18n( "Schema" ), m_schema); m_options->insertSeparator(); - m_options->insertItem( i18n("&History"), 3 ); - m_options->setItemEnabled(3, false); + + KAction *historyType = new KAction(i18n("History..."), 0, this, + SLOT(slotHistoryType()), this); + historyType->plug(m_options); + m_options->insertSeparator(); m_options->insertItem( SmallIconSet( "charset" ), i18n( "&Codec" ), m_codec); m_options->insertItem( SmallIconSet( "key_bindings" ), i18n( "&Keyboard" ), m_keytab ); @@ -699,6 +713,8 @@ config->writeEntry("scrollbar",n_scroll); config->writeEntry("keytab",n_keytab); config->writeEntry("WarnQuit", b_warnQuit); + if (se) + config->writeEntry("history", se->history().getSize()); if (args.count() > 0) config->writeEntry("konsolearguments", args); config->writeEntry("class",name()); @@ -772,6 +788,9 @@ te->setFrameStyle( b_framevis?(QFrame::WinPanel|QFrame::Sunken):QFrame::NoFrame ); te->setColorTable(sch->table()); + // History + m_histSize = config->readNumEntry("history",0); + KONSOLEDEBUG << "Hist size : " << m_histSize << endl; if (m_menuCreated) { @@ -988,18 +1007,10 @@ : QFrame::NoFrame ); } -void Konsole::setHistory(bool on) -{ - b_scroll = on; - m_options->setItemChecked(3,b_scroll); - if (se) se->setHistory( b_scroll ); -} void Konsole::opt_menu_activated(int item) { switch( item ) { - case 3: setHistory(!b_scroll); - break; case 5: setFullScreen(!b_fullscreen); break; case 8: @@ -1357,7 +1368,8 @@ s->setSchemaNo(schmno); //kdDebug()<<"setTitle Konsole 1319 "<< txt << endl; s->setTitle(txt); - s->setHistory(b_scroll); //FIXME: take from schema + + //s->setHistory(b_scroll); //FIXME: take from schema addSession(s); runSession(s); // activate and run @@ -1633,6 +1645,98 @@ toolBar()->updateRects(); // } } + + +////////////////////////////////////////////////////////////////////// + +HistoryTypeDialog::HistoryTypeDialog(const HistoryType& histType, QWidget *parent) + : KDialogBase(Plain, i18n("History Configuration"), + Help | Default | Ok | Cancel, Ok, + parent), + m_size(0) +{ + QFrame *mainFrame = plainPage(); + + QGridLayout *grid = new QGridLayout(mainFrame, 2, 2); + + QButtonGroup *btnGroup = new QButtonGroup(mainFrame); + btnGroup->hide(); + + QRadioButton *btnOff = new QRadioButton(i18n("Off"), mainFrame); + QRadioButton *btnBuffer = new QRadioButton(i18n("Buffer :"), mainFrame); + + btnGroup->insert(btnOff); + btnGroup->insert(btnBuffer); + + QObject::connect(btnOff, SIGNAL(clicked()), + this, SLOT(slotNoHistChoosen())); + + QObject::connect(btnBuffer, SIGNAL(clicked()), + this, SLOT(slotBufferHistChoosen())); + + grid->addWidget(btnOff, 0, 0); + grid->addWidget(btnBuffer, 1, 0); + + + m_size = new QSpinBox(0, 10 * 1000 * 1000, 1, mainFrame); + grid->addWidget(m_size, 1, 1); + + if (!histType.isOn()) { + + btnOff->setChecked(true); + slotNoHistChoosen(); + + } else { + + btnBuffer->setChecked(true); + m_size->setValue(histType.getSize()); + slotBufferHistChoosen(); + } + +} + +void HistoryTypeDialog::slotBufferHistChoosen() +{ + kdDebug() << "Konsole::slotBufferHistChoosen\n"; + m_isOff = false; + m_size->setEnabled(true); + m_size->setFocus(); +} + +void HistoryTypeDialog::slotNoHistChoosen() +{ + kdDebug() << "Konsole::slotNoHistChoosen\n"; + m_isOff = true; + m_size->setEnabled(false); +} + +unsigned int HistoryTypeDialog::bufferSize() const +{ + return m_isOff ? 0 : m_size->value(); +} + + + + +void Konsole::slotHistoryType() +{ + kdDebug() << "Konsole::slotHistoryType()\n"; + if (!se) return; + + HistoryTypeDialog dlg(se->history(), this); + if (dlg.exec()) { + + if (dlg.isOff()) + + se->setHistory(HistoryTypeNone()); + + else + + se->setHistory(HistoryTypeBlockArray(dlg.bufferSize())); + } +} + +////////////////////////////////////////////////////////////////////// void Konsole::slotWordSeps() { Index: konsole_part.C =================================================================== RCS file: /home/kde/kdebase/konsole/src/konsole_part.C,v retrieving revision 1.30 diff -u -r1.30 konsole_part.C --- konsole_part.C 2001/05/07 02:17:30 1.30 +++ konsole_part.C 2001/05/31 23:36:36 @@ -141,7 +141,7 @@ te->setColorTable(ctable); } - initial->setHistory(true); + initial->setHistory(HistoryTypeBlockArray(1000)); // setXMLFile("konsole_part.rc"); Index: session.C =================================================================== RCS file: /home/kde/kdebase/konsole/src/session.C,v retrieving revision 1.33 diff -u -r1.33 session.C --- session.C 2001/05/12 13:26:34 1.33 +++ session.C 2001/05/31 23:36:36 @@ -146,12 +146,12 @@ return title; } -void TESession::setHistory(bool on) +void TESession::setHistory(const HistoryType &hType) { - em->setHistory( on ); + em->setHistory(hType); } -bool TESession::history() +const HistoryType& TESession::history() { return em->history(); } --------------Boundary-00=_XJ48JJJ0S9A9YWNNISWE--