 
 // print a list of all displays
 // used by -l
-func listDisplays(var displayIDs:UnsafeMutablePointer<CGDirectDisplayID>, var count:Int) -> Void {
+func listDisplays(var displayIDs:UnsafeMutablePointer<CGDirectDisplayID>, let count:Int) -> Void {
     for i in 0..<count {
-        var di = displayInfo(displayIDs[i], nil)
-        println("Display \(i):  \(di.width) * \(di.height) @ \(di.frequency)Hz")
+        let di = displayInfo(displayIDs[i], mode:nil)
+        print("Display \(i):  \(di.width) * \(di.height) @ \(di.frequency)Hz")
     }
 }
 

        
    }
        
    println(help_msg)
}

func setDisplayMode(var display:CGDirectDisplayID, var mode:CGDisplayMode, var designatedWidth:UInt) -> Void {
    if CGDisplayModeIsUsableForDesktopGUI(mode) {
    
        var config = UnsafeMutablePointer<CGDisplayConfigRef>.alloc(1);
    
        var error = CGBeginDisplayConfiguration(config)
        if error == MyCGError.kCGErrorSuccess.rawValue {
            if nil != config {
                var option:CGConfigureOption = CGConfigureOption(kCGConfigurePermanently)
                CGConfigureDisplayWithDisplayMode(config.memory, display, mode, nil)
                var afterCheck = CGCompleteDisplayConfiguration(config.memory, option)
                if afterCheck != MyCGError.kCGErrorSuccess.rawValue {
                    CGCancelDisplayConfiguration(config.memory)
                }
            } else {
                println("Setting display mode failed")
            }
        }
    } else {
        println("This mode is unavailable for current desktop GUI")
    }
}

// list mode by display id
func listModesByDisplayID(var _displayID:CGDirectDisplayID?) -> [CGDisplayMode]? {
    if let displayID = _displayID {
        if let modeList = CGDisplayCopyAllDisplayModes(displayID, nil) {
            var modes = modeList.takeRetainedValue()

            var modesArray = [CGDisplayMode]()

            var count = CFArrayGetCount(modes)
            for i in 0..<count {
                var modeRaw = CFArrayGetValueAtIndex(modes, i)
                // https://github.com/FUKUZAWA-Tadashi/FHCCommander
                var mode = unsafeBitCast(modeRaw, CGDisplayMode.self)

                var di = displayInfo(displayID, mode)

                modesArray.append(mode)
            }

            nf.minimumIntegerDigits = 3 // XXX

            for i in 0..<modes.count {
                let di = displayInfo(display, mode:modes[i])
                print("       \(nf.stringFromNumber(di.width)!) * \(nf.stringFromNumber(di.height)!) @ \(di.frequency)Hz")
            }
        }
    }
