mirror of
https://github.com/ByteAtATime/raycast-linux.git
synced 2025-08-31 11:17:27 +00:00
feat(soulver): add ResultFormatter for evaluation results
This commit introduces the ResultFormatter function, which formats various evaluation results based on their type.
This commit is contained in:
parent
9913fb539f
commit
10d6709b44
2 changed files with 96 additions and 3 deletions
|
@ -0,0 +1,95 @@
|
|||
import SoulverCore
|
||||
import Foundation
|
||||
|
||||
func formatResult(result: EvaluationResult, customization: EngineCustomization) -> String {
|
||||
switch result {
|
||||
case .unitExpression(let unitExpression):
|
||||
let unit = unitExpression.unit
|
||||
return customization.longFormNameFor(unitIdentifier: unit.identifier)?.capitalized ?? unit.symbol
|
||||
case .unit(let scUnit):
|
||||
return customization.longFormNameFor(unitIdentifier: scUnit.identifier)?.capitalized ?? scUnit.symbol
|
||||
case .customUnit(let customUnit):
|
||||
return customUnit.name
|
||||
case .unitRate:
|
||||
return "Rate"
|
||||
case .unitRange:
|
||||
return "Range"
|
||||
|
||||
case .decimal:
|
||||
return "Number"
|
||||
case .percentage:
|
||||
return "Percentage"
|
||||
case .fraction:
|
||||
return "Fraction"
|
||||
case .scientificNotation:
|
||||
return "Scientific Notation"
|
||||
case .binary:
|
||||
return "Binary"
|
||||
case .octal:
|
||||
return "Octal"
|
||||
case .hex:
|
||||
return "Hexadecimal"
|
||||
case .multiplier:
|
||||
return "Multiplier"
|
||||
|
||||
case .date:
|
||||
return "Date"
|
||||
case .datespan:
|
||||
return "Date Range"
|
||||
case .iso8601:
|
||||
return "Date"
|
||||
case .timestamp:
|
||||
return "Timestamp"
|
||||
case .timespan:
|
||||
return "Duration"
|
||||
case .laptime:
|
||||
return "Lap Time"
|
||||
case .frametime:
|
||||
return "Frame Time"
|
||||
|
||||
case .gpsCoordinates:
|
||||
return "Coordinates"
|
||||
case .degreesMinutesSeconds:
|
||||
return "DMS Angle"
|
||||
case .place, .dynamicPlace:
|
||||
return "Place"
|
||||
|
||||
case .boolean:
|
||||
return "Boolean"
|
||||
case .resolution:
|
||||
return "Resolution"
|
||||
case .salesTax:
|
||||
return "Sales Tax"
|
||||
case .pitch:
|
||||
return "Pitch"
|
||||
case .substance:
|
||||
return "Substance"
|
||||
case .list:
|
||||
return "List"
|
||||
case .variable:
|
||||
return "Variable"
|
||||
case .statisticType:
|
||||
return "Statistic"
|
||||
|
||||
case .addingContext(_, let toResult):
|
||||
return formatResult(result: toResult, customization: customization)
|
||||
case .rawString:
|
||||
return "Text"
|
||||
case .error:
|
||||
return "Error"
|
||||
case .pending:
|
||||
return "Pending"
|
||||
case .failed:
|
||||
return "Failed"
|
||||
case .none:
|
||||
return "Empty"
|
||||
|
||||
case .decimalRate,
|
||||
.percentageRate,
|
||||
.customType:
|
||||
return String(describing: result.equivalentTokenType)
|
||||
|
||||
@unknown default:
|
||||
return "Unknown"
|
||||
}
|
||||
}
|
|
@ -77,10 +77,8 @@ public func evaluate(expression: UnsafePointer<CChar>) -> UnsafeMutablePointer<C
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
let resultType = String(describing: result.evaluationResult.equivalentTokenType)
|
||||
|
||||
let soulverResult = SoulverResult(value: result.stringValue, type: resultType)
|
||||
let soulverResult = SoulverResult(value: result.stringValue, type: formatResult(result: result.evaluationResult, customization: calculator.customization))
|
||||
|
||||
if let jsonData = try? encoder.encode(soulverResult),
|
||||
let jsonString = String(data: jsonData, encoding: .utf8) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue