Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup and fix #86

Merged
merged 1 commit into from
Nov 11, 2023
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
55 changes: 0 additions & 55 deletions app/src/main/java/io/atha/bababasic/ActivityMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -432,61 +432,6 @@ class ActivityMain : AppCompatActivity() {
}
}

private val EXAMPLES = mapOf(
"HELLO.bas" to """PRINT "HELLO WORLD"
PRINT "Καλημέρα κόσμε"
PRINT "ハローワールド"
INPUT "Name? ", A$
PRINT "HELLO " + A$
""",
"PRIME.bas" to """FOR I% = 1 TO 10000
J% = 3
N% = I% \ 2
ISPRIME% = (I% > 1) AND ((I% MOD 2 <> 0) OR (I% = 2))
WHILE J% <= N% AND ISPRIME% = -1
ISPRIME% = I% MOD J% <> 0
J% = J% + 2
WEND
IF ISPRIME% THEN PRINT STR$(I%), " is prime"
NEXT I%
""",
"FIB.bas" to """10 LET A = 0
20 LET B = 1
30 LET C = A + B
40 PRINT C
50 LET A = B
60 LET B = C
65 SLEEP 0.5
70 GOTO 30
""",
"INKEY.bas" to """PRINT "PRESS w,a,s,d TO MOVE THE STAR. PRESS q to QUIT."
X = 5
Y = 5
eventLoop:
LOCATE 2
FOR I = 0 TO 10
FOR J = 0 TO 10
IF X = I AND Y = J THEN PRINT "*"; ELSE PRINT " ";
NEXT J
PRINT
NEXT I
A$ = INKEY$
IF A$ <> "" THEN BEGIN
LOCATE 15
PRINT "YOU PRESSED " + A$
IF A$ = "a" THEN Y = Y - 1
IF A$ = "d" THEN Y = Y + 1
IF A$ = "w" THEN X = X - 1
IF A$ = "s" THEN X = X + 1
IF A$ = "q" THEN END
END IF
IF X < 0 THEN X = 0
IF X > 10 THEN X = 10
IF Y < 0 THEN Y = 0
IF Y > 10 THEN Y = 10
GOTO eventLoop"""
)

private val defaultScript = EXAMPLES["HELLO.bas"]!!

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down
61 changes: 61 additions & 0 deletions app/src/main/java/io/atha/bababasic/EXAMPLES.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.atha.bababasic

val EXAMPLES = mapOf(
"HELLO.bas" to """PRINT "Hello, world!"
PRINT "Καλημέρα, κόσμε!"
PRINT "ハロー, ワールド!"
PRINT
INPUT "Name? ", A$
PRINT "Hello, ", A$, "!"
INPUT "Year of birth? ", YOB%
CURRENTYEAR% = VAL(RIGHT${'$'}(DATE${'$'}, 4))
AGE% = CURRENTYEAR% - YOB%
PRINT "Your age is", AGE%
""",
"PRIME.bas" to """FOR I% = 1 TO 10000
J% = 3
N% = I% \ 2
ISPRIME% = (I% > 1) AND ((I% MOD 2 <> 0) OR (I% = 2))
WHILE J% <= N% AND ISPRIME% = -1
ISPRIME% = I% MOD J% <> 0
J% = J% + 2
WEND
IF ISPRIME% THEN PRINT STR$(I%), " is prime"
NEXT I%
""",
"FIB.bas" to """10 LET A = 0
20 LET B = 1
30 LET C = A + B
40 PRINT C
50 LET A = B
60 LET B = C
65 SLEEP 0.5
70 GOTO 30
""",
"INKEY.bas" to """PRINT "PRESS w,a,s,d TO MOVE THE STAR. PRESS q to QUIT."
X = 5
Y = 5
eventLoop:
LOCATE 2
FOR I = 0 TO 10
FOR J = 0 TO 10
IF X = I AND Y = J THEN PRINT "*"; ELSE PRINT " ";
NEXT J
PRINT
NEXT I
A$ = INKEY$
IF A$ <> "" THEN BEGIN
LOCATE 15
PRINT "YOU PRESSED " + A$
IF A$ = "a" THEN Y = Y - 1
IF A$ = "d" THEN Y = Y + 1
IF A$ = "w" THEN X = X - 1
IF A$ = "s" THEN X = X + 1
IF A$ = "q" THEN END
END IF
IF X < 0 THEN X = 0
IF X > 10 THEN X = 10
IF Y < 0 THEN Y = 0
IF Y > 10 THEN Y = 10
GOTO eventLoop"""
)
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class TermuxTerminalViewClient(
return
}
val urls = urlSet.toTypedArray()
Collections.reverse(Arrays.asList(*urls)) // Latest first.
mutableListOf(*urls).reverse() // Latest first.

// Click to copy url to clipboard:
val dialog: AlertDialog = AlertDialog.Builder(mActivity).setItems(
Expand All @@ -659,7 +659,7 @@ class TermuxTerminalViewClient(
val lv =
dialog.listView // this is a ListView with your "buds" in it
lv.onItemLongClickListener =
AdapterView.OnItemLongClickListener { parent: AdapterView<*>?, view: View?, position: Int, id: Long ->
AdapterView.OnItemLongClickListener { _: AdapterView<*>?, _: View?, position: Int, _: Long ->
dialog.dismiss()
val url = urls[position] as String
ShareUtils.openUrl(mActivity, url)
Expand All @@ -677,14 +677,14 @@ class TermuxTerminalViewClient(
mActivity, TermuxConstants.TERMUX_APP_NAME + " Report Issue",
"debug info?", //mActivity.getString(R.string.msg_add_termux_debug_info),
"yes", // mActivity.getString(R.string.action_yes),
{ dialog: DialogInterface?, which: Int ->
{ _: DialogInterface?, _: Int ->
reportIssueFromTranscript(
transcriptText,
true
)
},
"no", //mActivity.getString(R.string.action_no),
{ dialog: DialogInterface?, which: Int ->
{ _: DialogInterface?, _: Int ->
reportIssueFromTranscript(
transcriptText,
false
Expand Down
Loading