sagesession.h 2.6 KB
Newer Older
1
/*
2
    SPDX-License-Identifier: GPL-2.0-or-later
3
4
    SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
*/
5
6
7
8
9
10
11

#ifndef _SAGESESSION_H
#define _SAGESESSION_H

#include "session.h"
#include "expression.h"

12
#include <KDirWatch>
13
#include <QProcess>
14

15
class SageExpression;
16
17
18
class KPtyProcess;


Alexander Rieder's avatar
Alexander Rieder committed
19
class SageSession : public Cantor::Session
20
21
22
23
{
  Q_OBJECT
  public:
    static const QByteArray SagePrompt;
24
    static const QByteArray SageAlternativePrompt;
25

26
27
28
29
    //small helper class to deal with sage versions
    //Note: major version -1 is treated as most current
    class VersionInfo{
      public:
Yuri Chornoivan's avatar
Yuri Chornoivan committed
30
        explicit VersionInfo(int major = -1, int minor = -1);
31

Alexander Semke's avatar
Alexander Semke committed
32
33
34
35
36
37
        //bool operator <=(VersionInfo v2);
        bool operator <(VersionInfo other) const;
        bool operator <=(VersionInfo other) const;
        bool operator >(VersionInfo other) const;
        bool operator >=(VersionInfo other) const;
        bool operator ==( VersionInfo other) const;
38

39
40
41
42
        // These are not called major() and minor() because some libc's have
        // macros with those names.
        int majorVersion() const;
        int minorVersion() const;
43
44
45
46
47
48
      private:
        int m_major;
        int m_minor;
    };


Yuri Chornoivan's avatar
Yuri Chornoivan committed
49
    explicit SageSession( Cantor::Backend* backend);
50
    ~SageSession() override;
51

52
53
    void login() override;
    void logout() override;
54

55
    Cantor::Expression* evaluateExpression(const QString& command,Cantor::Expression::FinishingBehavior behave = Cantor::Expression::FinishingBehavior::DoNotDelete, bool internal = false) override;
56

57
    void runFirstExpression() override;
58

59
    void interrupt() override;
60

61
    void sendInputToProcess(const QString& input);
62

63
    void setTypesettingEnabled(bool enable) override;
64
    void setWorksheetPath(const QString& path) override;
65

66
67
    Cantor::CompletionObject* completionFor(const QString& command, int index=-1) override;
    QSyntaxHighlighter* syntaxHighlighter(QObject* parent) override;
68

69
    VersionInfo sageVersion();
70
  public Q_SLOTS:
71
72
73
    void readStdOut();
    void readStdErr();

74
  private Q_SLOTS:
75
76
77
    void currentExpressionChangedStatus(Cantor::Expression::Status);
    void processFinished(int exitCode, QProcess::ExitStatus);
    void reportProcessError(QProcess::ProcessError);
78
79
80
    void fileCreated(const QString& path);

  private:
81
    void defineCustomFunctions();
82
    bool updateSageVersion();
83
84
  private:
    KPtyProcess* m_process;
85
    bool m_isInitialized;
86
87
    QString m_tmpPath;
    KDirWatch m_dirWatch;
88
    bool m_waitingForPrompt;
89
    QString m_outputCache;
90
    VersionInfo m_sageVersion;
91
    bool m_haveSentInitCmd;
92
    QString m_worksheetPath;
93
94
95
};

#endif /* _SAGESESSION_H */