Linux Notepad

Linux specific questions.
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Linux Notepad

Postby Sigord » Jan 20, 2014 7:26

As some here may have noticed in my Amateurish way, I am upgrading old QB of mine from many years ago and other Basic to create Linux Freeware at http://www.sigord.co.uk//SubmitsLinux/LinuxSoftware.htm

I use the excellent online coder at http://fbc.deltalabs.de/ In order to produce a simple version of my HTML coder I can use below to provide the option to allow the user to edit HTML or open the Web Page. Is there an alternative I can use instead of Notepad under Linux to edit HTM for Mint, Ubunto,and maybe Slackware Puppy which run all run my efforts?

I could perhaps use CPY to make a TXT file for the user to open with the Linux Editor and copy it back to Menu.htm, but that seems a bit crude. The BAS code is available to anyone who emails me, which I may make available online soon.

Code: Select all

    Sub wpage
        Shell "Notepad.exe Menu.htm"
    End Sub
   
    Sub html
        Shell "Menu.htm"
    End Sub   
David Watson
Posts: 30
Joined: May 15, 2013 16:48
Location: England

Re: Linux Notepad

Postby David Watson » Jan 20, 2014 10:42

If you are looking for a html editor then Bluefish is a popular choice, if you just want a simple Notepad substitute then try Leafpad or Mousepad. You should find all three in your package manager.
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: Linux Notepad

Postby Sigord » Jan 20, 2014 15:52

Thanks but the Shell command below is ignored once the code is compiled for Linux. So how so I get to recognise your suggestions please?

Code: Select all

Dim d as String

ScreenRes 800,600
Locate 10,10
do
    Input "Enter Shell command";d
    Shell d
Loop While d <>""
Beep : End
David Watson
Posts: 30
Joined: May 15, 2013 16:48
Location: England

Re: Linux Notepad

Postby David Watson » Jan 20, 2014 17:14

I've just tried your program on my Mint/Mate set up and it worked fine. Entering pluma t.html at the Enter Shell command prompt brought up my text editor with the file t.html opened. What text editor are you testing it with?
Landeel
Posts: 699
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Re: Linux Notepad

Postby Landeel » Jan 20, 2014 17:23

Maybe this will help:

Code: Select all

...
FileCopy "Menu.htm","Menu.htm.txt"
Shell "xdg-open Menu.htm.txt"
...
FileCopy "Menu.htm.txt","Menu.htm"
Shell "xdg-open Menu.htm"
...


xdg-open - opens a file or URL in the user's preferred application
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: Linux Notepad

Postby Sigord » Jan 20, 2014 18:06

Thanks guys I will experiment. But maybe I am asking to much.

Just as with other Basics using a ShelllExec routine, I was hoping just as you can activate almost ANY file under Windows or Linux like TXT, EXE, COM. MP3, MID etc by its File Association settings by just clicking on it. Then likewise with the FB Shell function. I was hoping the same works with Linux once the code is compiled.

That way I can activate any HTM file using say a Firefox File Association under Linux, or a TXT with Notepad under Windows.
Landeel
Posts: 699
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Re: Linux Notepad

Postby Landeel » Jan 20, 2014 20:28

That's exactly what "xdg-open" does.
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: Linux Notepad

Postby Sigord » Jan 21, 2014 10:57

Thanks again everyone, "xdg-open" does work OK under Linux. But before opening an HTM file it claims Firefox is already in use, perhaps because it is not online at present. But I decided to make the user enter the name of the default TXT editor, such a my ver 13 Mint uses gedit.

Is there a way we can detect if the program is running in Windows or Linux, so that minor adjustments can be made accordingly.
Landeel
Posts: 699
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Re: Linux Notepad

Postby Landeel » Jan 21, 2014 13:19

Code: Select all

#ifdef __FB_WIN32__
   ' you're running on windows
#else
   ' you're not running on windows - so you're probably running on linux or another *nix
#endif


In case you make a DOS version, there's __FB_DOS__ too.
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: Linux Notepad

Postby Sigord » Jan 21, 2014 14:03

Thanks. But sorry to be a bit 'thick' being a put 80 year old amateur programmer, what indication can I get from below as to which OS is in use?

Code: Select all

#ifdef __FB_WIN32__
   ' you're running on windows
#else
   ' you're not running on windows - so you're probably running on linux or another *nix
#endif

Print "what?"
sleep
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Re: Linux Notepad

Postby sir_mud » Jan 21, 2014 17:47

Code: Select all

#ifdef __FB_WIN32__
    print "This code only runs on windows.
#else
    #ifdef __FB_LINUX__
        print "This code will run on linux.
    #else
        print "And this code will run on dos.
    #endif
#endif
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: Linux Notepad

Postby Sigord » Jan 21, 2014 18:46

Thanks again
Sigord
Posts: 153
Joined: Mar 14, 2013 9:54
Location: Hastings UK
Contact:

Re: Linux Notepad

Postby Sigord » Jan 23, 2014 8:16

Just as a matter if interest though the #ifdef __FB_WIN32__ routine above is accepted by my 64 bit Windows 7 it invokes an error run under my Mint ver 13

Also using xdg-open in below does not always wok in my Mint with some files such as gedit So I have included an option as to whether to use it or not below.

Code: Select all

Dim as String d,e,k

Screen 17
color 0,15 : Paint(10,10),15 : Cls : Locate 5,1

do
    Print tab(10); : Input "Enter command or nothing to quit";d
    Print tab(20);"Prefix with xdg-open Y/N ?"
   
    do
        k = inkey
        Sleep 20
    Loop while k = ""
   
    if k = "y" or k = "Y" then e = "xdg-open " + d else e = d       
    Shell e
Loop While d <>""

End
sir_mud
Posts: 1401
Joined: Jul 29, 2006 3:00
Location: US
Contact:

Re: Linux Notepad

Postby sir_mud » Jan 23, 2014 18:31

Looks like i missed the end quotes on the Linux and DOS tracks there, that would explain the error. With xdg-open you can check it's return value and try a different command automatically, man xdg-open will show you the possible values it will return, mine seems to exclude 0 which would mean no error.
Landeel
Posts: 699
Joined: Jan 25, 2007 10:32
Location: Brazil
Contact:

Re: Linux Notepad

Postby Landeel » Jan 25, 2014 18:37

if k = "y" or k = "Y" then e = "xdg-open " + d else e = d
Shell e


Hm, I don't think this will work if the filename or the path has spaces...

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 1 guest