Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 21 additions & 39 deletions PythonScript/src/ConsoleDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ ConsoleDialog::ConsoleDialog() :
m_scintilla(NULL),
m_hInput(NULL),
m_console(NULL),
m_prompt(">>> "),
m_currentPrompt(">>> "),
m_standardPrompt(">>> "),
m_continuePrompt("... "),
m_originalInputWndProc(NULL),
m_hTabIcon(NULL),
m_currentHistory(0),
Expand Down Expand Up @@ -84,8 +86,8 @@ void ConsoleDialog::initDialog(HINSTANCE hInst, NppData& nppData, ConsoleInterfa
{
m_colorOutput = false;
}
m_prompt = ConfigFile::getInstance()->getSetting(_T("ADDEXTRALINETOOUTPUT")) == _T("1") ? m_prompt.insert(0, "\n") : m_prompt;

m_standardPrompt = ConfigFile::getInstance()->getSetting(_T("ADDEXTRALINETOOUTPUT")) == _T("1") ? m_standardPrompt.insert(0, "\n") : m_standardPrompt;
m_currentPrompt = m_standardPrompt;
//Window::init(hInst, nppData._nppHandle);
createOutputWindow(nppData._nppHandle);

Expand Down Expand Up @@ -433,7 +435,7 @@ void ConsoleDialog::runStatement()
std::shared_ptr<char> charBuffer = WcharMbcsConverter::tchar2char(buffer);
delete [] buffer;

writeCmdText(m_prompt.size(), m_prompt.c_str());
writeCmdText(m_currentPrompt.size(), m_currentPrompt.c_str());
writeCmdText(strlen(charBuffer.get()), charBuffer.get());
writeCmdText(1, "\n");
SetWindowText(hText, _T(""));
Expand All @@ -452,16 +454,16 @@ void ConsoleDialog::stopStatement()
}


void ConsoleDialog::setPrompt(const char *prompt)
void ConsoleDialog::setPrompt(std::string prompt)
{
m_prompt = prompt;
::SetWindowTextA(::GetDlgItem(_hSelf, IDC_PROMPT), (m_prompt.rfind('\n', 0) == 0) ? m_prompt.substr(1, m_prompt.size() - 1).c_str() : m_prompt.c_str());
m_currentPrompt = prompt;
::SetWindowTextA(::GetDlgItem(_hSelf, IDC_PROMPT), (prompt.rfind('\n', 0) == 0) ? prompt.substr(1, prompt.size() - 1).c_str() : prompt.c_str());
}

const char * ConsoleDialog::getPrompt()
{
return m_prompt.c_str();
}
std::string ConsoleDialog::getStandardPrompt(){ return m_standardPrompt;}

std::string ConsoleDialog::getContinuePrompt(){ return m_continuePrompt;}


void ConsoleDialog::createOutputWindow(HWND hParentWindow)
{
Expand Down Expand Up @@ -510,12 +512,10 @@ void ConsoleDialog::createOutputWindow(HWND hParentWindow)
callScintilla(SCI_STYLESETSIZE, 4 /* = style number */, 8 /* = size in points */);
callScintilla(SCI_STYLESETFORE, 4, RGB(199, 175, 7)); // mucky yellow


// 5 stderr warning without hotspot
callScintilla(SCI_STYLESETSIZE, 5 /* = style number */, 8 /* = size in points */);
callScintilla(SCI_STYLESETFORE, 5, RGB(255, 128, 64)); // orange


// 6 is hotspot, stdout, warning
callScintilla(SCI_STYLESETSIZE, 6 /* = style number */, 8 /* = size in points */);
callScintilla(SCI_STYLESETFORE, 6, RGB(199, 175, 7)); // mucky yellow
Expand All @@ -528,14 +528,13 @@ void ConsoleDialog::createOutputWindow(HWND hParentWindow)
callScintilla(SCI_STYLESETUNDERLINE, 7 /* = style number */, 1 /* = underline */);
callScintilla(SCI_STYLESETHOTSPOT, 7, 1);

// 8 is colored stdout
callScintilla(SCI_STYLESETSIZE, 8 /* = style number */, 8 /* = size in points */);
callScintilla(SCI_STYLESETFORE, 8, m_colorOutput ? m_user_color : 0); // green

// 8 is colored stdout inidcator
intptr_t defaultColor = callScintilla(SCI_STYLEGETFORE, 0, 0);
callScintilla(SCI_INDICSETSTYLE, 8 /* = indicator number */, INDIC_TEXTFORE);
callScintilla(SCI_INDICSETFORE, 8, m_colorOutput ? m_user_color : defaultColor); // green

callScintilla(SCI_USEPOPUP, 0);
callScintilla(SCI_SETLEXER, SCLEX_CONTAINER);


}

LRESULT ConsoleDialog::scintillaWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Expand Down Expand Up @@ -609,35 +608,18 @@ void ConsoleDialog::writeText(size_t length, const char *text)
void ConsoleDialog::writeColoredText(size_t length, const char *text)
{
size_t docLength = (size_t)callScintilla(SCI_GETLENGTH);
size_t realLength = length;
callScintilla(SCI_SETREADONLY, 0);
for (idx_t i = 0; i < length; ++i)
Copy link
Collaborator

@chcg chcg Jul 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ClaudiaFrank Why is this no longer needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the complete text should be colored - no need for special treatments like
in writeerror function but to be honest, I don't see why this special treamtent is needed at all or
what the benefit is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added with:

Revision: d725887
Author: Dave Brotherstone [email protected]
Date: 13.08.2010 00:00:27
Message:
Stripped the \r from console output

  • console.run output now a bit nicer if commands output \r\n

Modified: PythonScript/src/ConsoleDialog.cpp

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I don't see the necessity.
Example with console.write and print. Note, write mehtod does not, contrary to print,
add an eol automatically to the end of the text.

>>> console.write('hello\r')
hello
>>> console.write('hello\n')
hello
>>> console.write('hello\r\n')
hello
>>> print('hello\r')
hello
>>> print('hello\n')
hello

>>> print('hello\r\n')
hello

>>>

grafik

The different behavior of print is related to python as it is internally using \n only, that
is the reason why the 2nd and third are having an additional line - but I don't think that
this was the reason to introduce this logis at all.
Coult it be that scintilla from 2010 had problems with different EOLs?
I did a search on scintilla google groups but I haven't found one.
Today, clearly, it hasn't. I can reintroudce the code, I don't mind - Just not sure if it is needed anymore. What about keeping it for some time and if no one complains remove the logic from the
others as well?
As said, I don't mind, if I should keep it the same like the others I will do so.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be ok, let's see if someone finds an issue with it

{
if (text[i] == '\r')
{
if (i)
{
callScintilla(SCI_APPENDTEXT, i, reinterpret_cast<LPARAM>(text));
}
text += i + 1;
length -= i + 1;
realLength--;
i = 0;
}
}

if (length > 0)
{
callScintilla(SCI_APPENDTEXT, length, reinterpret_cast<LPARAM>(text));
}

callScintilla(SCI_SETREADONLY, 1);
callScintilla(SCI_STARTSTYLING, docLength, 0x01);
callScintilla(SCI_SETSTYLING, realLength, m_colorOutput ? 8 : 0);


callScintilla(SCI_COLOURISE, docLength, -1);
callScintilla(SCI_GOTOPOS, docLength + realLength);
callScintilla(SCI_SETINDICATORCURRENT, 8);
callScintilla(SCI_INDICATORFILLRANGE, docLength, length);
callScintilla(SCI_GOTOPOS, docLength+length);
}

void ConsoleDialog::writeError(size_t length, const char *text)
Expand Down
9 changes: 6 additions & 3 deletions PythonScript/src/ConsoleDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class ConsoleDialog : public DockingDlgInterface
void writeColoredText(size_t length, const char *text);
void writeError(size_t length, const char *text);
void clearText();
void setPrompt(const char *prompt);
const char * getPrompt();
void setPrompt(std::string prompt);
std::string getStandardPrompt();
std::string getContinuePrompt();
HWND getScintillaHwnd() { return m_scintilla; }

void giveInputFocus() { SetFocus(m_hInput); }
Expand Down Expand Up @@ -83,7 +84,9 @@ class ConsoleDialog : public DockingDlgInterface
static WNDPROC s_originalScintillaWndProc;
HWND m_hInput; // Input TextBox
ConsoleInterface *m_console;
std::string m_prompt;
std::string m_standardPrompt;
std::string m_continuePrompt;
std::string m_currentPrompt;
WNDPROC m_originalInputWndProc;
HICON m_hTabIcon;

Expand Down
81 changes: 66 additions & 15 deletions PythonScript/src/CreateWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@

}

exclusions = [ 'FormatRange', 'GetCharacterPointer', 'GetRangePointer' ]

def Contains(s,sub):
return s.find(sub) != -1
exclusions = [ 'FormatRange',]


def symbolName(v):
Expand Down Expand Up @@ -317,6 +314,56 @@ def annotationSetTextBody(v, out):
'''.format(v["Param2Name"], v["Param2Name"], symbolName(v), v["Param1Name"]))


def getSetDocPointerBody(v, out):
traceCall(v, out)
checkDisallowedInCallback(v, out)
out.write(
''' callScintilla({0}, 0, {1});
'''.format(symbolName(v), v["Param2Name"]))


def getAddRefDocumentBody(v, out):
traceCall(v, out)
checkDisallowedInCallback(v, out)
out.write(
''' callScintilla({0}, 0, {1});
'''.format(symbolName(v), v["Param2Name"]))


def getReleaseDocumentBody(v, out):
traceCall(v, out)
checkDisallowedInCallback(v, out)
out.write(
''' callScintilla({0}, 0, {1});
'''.format(symbolName(v), v["Param2Name"]))


def getPrivateLexerCallBody(v, out):
traceCall(v, out)
checkDisallowedInCallback(v, out)
out.write(
''' return callScintilla({0}, {1}, {2});
'''.format(symbolName(v), v["Param1Name"], v["Param2Name"]))


def getGetRangePointerBody(v, out):
out.write(
''' GILRelease release;
const char *charPtr = reinterpret_cast<const char*>(callScintilla({0}, {2}, {3}));
release.reacquire();
return {1}(charPtr, charPtr + {3});
'''.format(symbolName(v), v["ReturnType"], v["Param1Name"], v["Param2Name"]))


def getGetCharacterPointerBody(v, out):
out.write(
''' GILRelease release;
const char *charPtr = reinterpret_cast<const char*>(callScintilla({0}));
release.reacquire();
return {1}(charPtr);
'''.format(symbolName(v), v["ReturnType"]))


def standardBody(v, out):
# We always release the GIL. For standard getters, this shouldn't really be necessary.
# However, it doesn't appear to affect performance to dramatically (yet!), so we'll leave it in until
Expand Down Expand Up @@ -409,7 +456,13 @@ def getPythonParamNamesQuoted(param1Type, param1Name, param2Type, param2Name):
specialCases = {
'GetStyledText' : ('boost::python::tuple', 'int', 'start', 'int', 'end', getStyledTextBody),
'GetLine': ('boost::python::str', 'int', 'line', '', '', getLineBody),
'AnnotationSetText' : ('void', 'int', 'line', 'boost::python::object', 'text', annotationSetTextBody)
'AnnotationSetText' : ('void', 'int', 'line', 'boost::python::object', 'text', annotationSetTextBody),
'SetDocPointer' :('void', '','','intptr_t', 'pointer', getSetDocPointerBody),
'AddRefDocument' :('void', '','', 'intptr_t', 'doc', getAddRefDocumentBody),
'ReleaseDocument' :('void', '','', 'intptr_t', 'doc', getReleaseDocumentBody),
'PrivateLexerCall' :('intptr_t', 'intptr_t','operation','intptr_t', 'pointer', getPrivateLexerCallBody),
'GetCharacterPointer' :('boost::python::str', '','','', '', getGetCharacterPointerBody),
'GetRangePointer' :('boost::python::str', 'int','position','int', 'rangeLength', getGetRangePointerBody)
}


Expand Down Expand Up @@ -496,16 +549,14 @@ class PythonCompatibleStrBuffer
sig = mapSignature((v["Param1Type"], v["Param1Name"], v["Param2Type"], v["Param2Name"]))

if sig is not None:
# print '{:<45} {} ==>> {}'.format(v["Name"], v["ReturnType"], sig[0])
v["ReturnType"] = 'intptr_t' if sig[0] == 'int' else sig[0]
v["ReturnType"] = 'intptr_t' if sig[0] in ['int', 'int pointer'] else sig[0]
v["Param1Type"] = sig[1]
v["Param2Type"] = sig[2]

body = sig[3]
else:
# print '{:<45} {} -->> {}'.format(v["Name"], v["ReturnType"], mapType(v["ReturnType"]))
#if !checkStandardTypeIsKnown(v["ReturnType", v["Param1Type"], v["Param1Name"], v["Param2Type"], v["Param2Name"]):
# print("Warning: unrecognised parameter combination for {0}({1} {2}, {3} {4})".format(v["Name"], v["Param1Type"], v["Param1Name"], v["Param2Type"], v["Param2Name"]))

v["ReturnType"] = 'intptr_t' if v["ReturnType"] in ['int', 'position'] else mapType(v["ReturnType"])
v["Param1Type"] = mapType(v["Param1Type"])
v["Param2Type"] = mapType(v["Param2Type"])
Expand Down Expand Up @@ -568,7 +619,7 @@ def writeHFile(f,out):

out.write("\t/** " + "\n\t * ".join(v["Comment"]) + "\n */\n")

out.write("\t");
out.write("\t")
out.write(getSignature(v).replace(' ScintillaWrapper::', ' '))
out.write(";\n\n")

Expand Down Expand Up @@ -659,7 +710,7 @@ def writeEnumsWrapperFile(f, out):
out.write('\n\t\t.value("{0}", PYSCR_{1})'.format(val[0][takeEnumValueFromPosition:].upper(), val[0]))
out.write(';\n\n')

out.write('\tboost::python::enum_<ScintillaNotification>("SCINTILLANOTIFICATION")'.format(name, name.upper()))
out.write('\tboost::python::enum_<ScintillaNotification>("SCINTILLANOTIFICATION")') #.format(name, name.upper()))

for name in f.order:
v = f.features[name]
Expand All @@ -668,7 +719,7 @@ def writeEnumsWrapperFile(f, out):
out.write('\n\t\t.value("{0}", PYSCR_SCN_{1})'.format(name.upper(), name.upper()))
out.write(';\n\n')

out.write('\tboost::python::enum_<ScintillaMessage>("SCINTILLAMESSAGE")'.format(name, name.upper()))
out.write('\tboost::python::enum_<ScintillaMessage>("SCINTILLAMESSAGE")') #.format(name, name.upper()))
for name in f.order:
v = f.features[name]
if v["Category"] != "Deprecated":
Expand All @@ -688,7 +739,7 @@ def writeScintillaDoc(f, out):
continue

if v["Name"] in specialCases:
(v["ReturnType"], v["Param1Type"], v["Param1Name"], v["Param2Type"], v["Param2Name"], body) = specialCases[v["Name"]]
(v["ReturnType"], v["Param1Type"], v["Param1Name"], v["Param2Type"], v["Param2Name"], _) = specialCases[v["Name"]]
else:
sig = mapSignature((v["Param1Type"], v["Param1Name"], v["Param2Type"], v["Param2Name"]))

Expand Down Expand Up @@ -765,10 +816,10 @@ def CopyWithInsertion(input, output, genfn, definition):
for line in input.readlines():
if copying:
output.write(line)
if Contains(line, "/* ++Autogenerated"):
if "/* ++Autogenerated" in line:
copying = 0
genfn(definition, output)
if Contains(line, "/* --Autogenerated"):
if "/* --Autogenerated" in line:
copying = 1
output.write(line)

Expand Down
Loading